qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
protocol.h
Go to the documentation of this file.
1
26
27#ifndef QB_IO_ASYNC_PROTOCOL_H
28#define QB_IO_ASYNC_PROTOCOL_H
29
31
32namespace qb::io::async {
33
43class IProtocol {
44 bool _status = true;
45 bool _should_flush = true;
46public:
51 virtual ~IProtocol() = default;
52
65 virtual std::size_t getMessageSize() noexcept = 0;
66
79 virtual void onMessage(std::size_t size) noexcept = 0;
80
88 virtual void reset() noexcept = 0;
89
90public:
96 [[nodiscard]] bool
97 ok() const noexcept {
98 return _status;
99 }
100
108 void
109 not_ok() noexcept {
110 _status = false;
111 }
112
117 void set_should_flush(bool should_flush) noexcept {
118 _should_flush = should_flush;
119 }
120
125 bool should_flush() const noexcept {
126 return _should_flush;
127 }
128};
129
145template <typename _IO_>
146class AProtocol : public IProtocol {
162 friend typename _IO_::base_io_t;
163
164
165protected:
166 _IO_ &_io;
167
171 AProtocol() = delete;
172
177 AProtocol(_IO_ &io) noexcept
178 : _io(io) {}
179
183 virtual ~AProtocol() = default;
184
185 // Pure virtual methods inherited from IProtocol, to be implemented by concrete protocols.
186
193 virtual std::size_t getMessageSize() noexcept = 0;
194
201 virtual void onMessage(std::size_t size) noexcept = 0;
202
207 virtual void reset() noexcept = 0;
208
209
210};
211
212} // namespace qb::io::async
213
214#endif // QB_IO_ASYNC_PROTOCOL_H
virtual ~AProtocol()=default
Virtual destructor.
AProtocol(_IO_ &io) noexcept
Constructor that associates the protocol with an I/O component.
Definition protocol.h:177
AProtocol()=delete
Default constructor is deleted to ensure an I/O component is always associated.
virtual void onMessage(std::size_t size) noexcept=0
Processes a complete message from the input buffer of the associated I/O component.
virtual std::size_t getMessageSize() noexcept=0
Determines the size of the next complete message in the input buffer of the associated I/O component.
virtual void reset() noexcept=0
Resets the internal parsing state of the protocol.
_IO_ & _io
Reference to the I/O component instance that this protocol is associated with.
Definition protocol.h:166
Base interface for all message processing protocols.
Definition protocol.h:43
bool should_flush() const noexcept
Gets the flag indicating whether the protocol should flush the input buffer after processing a messag...
Definition protocol.h:125
virtual ~IProtocol()=default
Virtual destructor.
void set_should_flush(bool should_flush) noexcept
Sets the flag indicating whether the protocol should flush the input buffer after processing a messag...
Definition protocol.h:117
virtual void onMessage(std::size_t size) noexcept=0
Processes a complete message that has been identified in the input buffer.
void not_ok() noexcept
Marks the protocol as being in an invalid or non-operational state.
Definition protocol.h:109
virtual std::size_t getMessageSize() noexcept=0
Determines the size of the next complete message in the input buffer.
virtual void reset() noexcept=0
Resets the internal state of the protocol.
bool ok() const noexcept
Checks if the protocol is in a valid operational state.
Definition protocol.h:97
CRTP base class for managing bidirectional asynchronous I/O operations with protocol processing.
Definition io.h:938
Advanced type traits and metaprogramming utilities for the QB Framework.