qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::async::IProtocol Interface Referenceabstract

Base interface for all message processing protocols. More...

#include <protocol.h>

Inheritance diagram for qb::io::async::IProtocol:

Public Member Functions

virtual ~IProtocol ()=default
 Virtual destructor.
virtual std::size_t getMessageSize () noexcept=0
 Determines the size of the next complete message in the input buffer.
virtual void onMessage (std::size_t size) noexcept=0
 Processes a complete message that has been identified 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.
void not_ok () noexcept
 Marks the protocol as being in an invalid or non-operational state.
void set_should_flush (bool should_flush) noexcept
 Sets the flag indicating whether the protocol should flush the input buffer after processing a message.
bool should_flush () const noexcept
 Gets the flag indicating whether the protocol should flush the input buffer after processing a message.

Detailed Description

Base interface for all message processing protocols.

This interface defines the essential methods that all protocol implementations must provide for message framing (identifying message boundaries in a byte stream) and processing.

Constructor & Destructor Documentation

◆ ~IProtocol()

virtual qb::io::async::IProtocol::~IProtocol ( )
virtualdefault

Virtual destructor.

Ensures proper cleanup for derived protocol classes.

Member Function Documentation

◆ getMessageSize()

virtual std::size_t qb::io::async::IProtocol::getMessageSize ( )
pure virtualnoexcept

Determines the size of the next complete message in the input buffer.

This method must be implemented by concrete protocols to examine the current input buffer (typically accessed via the associated I/O component) and determine if a complete message is available according to the protocol's framing rules.

Returns
Size of the next complete message in bytes (including any headers or delimiters that are part of the message unit). Returns 0 if no complete message is yet available in the buffer, indicating more data is needed.
Note
This method should not consume data from the buffer; it only inspects it.

Implemented in qb::io::async::AProtocol< _IO_ >, qb::io::async::AProtocol< IO_ >, qb::io::protocol::accept< _IO_, _Socket >, qb::io::protocol::accept< acceptor, typename _Prot::socket_type >, qb::io::protocol::handshake< _IO_ >, qb::protocol::base::byte_terminated< _IO_, _EndByte >, qb::protocol::base::byte_terminated< _IO_, '\0' >, qb::protocol::base::byte_terminated< IO_, '\0'>, qb::protocol::base::bytes_terminated< _IO_, _Trait >, qb::protocol::base::size_as_header< _IO_, _Size >, and qb::protocol::base::size_as_header< _IO_, uint16_t >.

◆ onMessage()

virtual void qb::io::async::IProtocol::onMessage ( std::size_t size)
pure virtualnoexcept

Processes a complete message that has been identified in the input buffer.

This method is called by the framework when getMessageSize() has returned a non-zero size. The implementation should process the message of the given size starting from the beginning of the current input buffer. After processing, the derived I/O component is usually responsible for flushing these size bytes from its input buffer.

Parameters
sizeThe size of the complete message to process, as determined by getMessageSize().
Note
The protocol should typically dispatch the parsed message to a handler in its associated I/O component (e.g., by calling _io.on(MyProtocol::message{...})).

Implemented in qb::io::async::AProtocol< _IO_ >, qb::io::async::AProtocol< IO_ >, qb::io::protocol::accept< _IO_, _Socket >, qb::io::protocol::accept< acceptor, typename _Prot::socket_type >, qb::io::protocol::handshake< _IO_ >, qb::protocol::json< IO_ >, qb::protocol::json_packed< IO_ >, qb::protocol::text::basic_text< _IO_, _StringTrait, _Sep >, qb::protocol::text::basic_text< _IO_, const std::string_view, '\0'>, qb::protocol::text::basic_text< _IO_, const std::string_view, '\n'>, qb::protocol::text::basic_text< _IO_, std::string, '\0'>, and qb::protocol::text::basic_text< _IO_, std::string, '\n'>.

◆ reset()

virtual void qb::io::async::IProtocol::reset ( )
pure virtualnoexcept

◆ ok()

bool qb::io::async::IProtocol::ok ( ) const
inlinenodiscardnoexcept

Checks if the protocol is in a valid operational state.

Returns
true if the protocol is considered okay and can continue processing, false if it has encountered an unrecoverable error or has been marked as not okay.

◆ not_ok()

void qb::io::async::IProtocol::not_ok ( )
inlinenoexcept

Marks the protocol as being in an invalid or non-operational state.

This method can be called by the protocol implementation (or externally) to indicate that it has encountered an unrecoverable parsing error or that the connection should be closed after processing any pending data. The I/O component might check this status via ok().

◆ set_should_flush()

void qb::io::async::IProtocol::set_should_flush ( bool should_flush)
inlinenoexcept

Sets the flag indicating whether the protocol should flush the input buffer after processing a message.

Parameters
should_flushtrue if the protocol should flush the input buffer after processing a message, false otherwise.

◆ should_flush()

bool qb::io::async::IProtocol::should_flush ( ) const
inlinenoexcept

Gets the flag indicating whether the protocol should flush the input buffer after processing a message.

Returns
true if the protocol should flush the input buffer after processing a message, false otherwise.