qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::async::AProtocol< _IO_ > Class Template Referenceabstract

Abstract base class for I/O-component-aware protocols (CRTP). More...

#include <protocol.h>

Inheritance diagram for qb::io::async::AProtocol< _IO_ >:
Collaboration diagram for qb::io::async::AProtocol< _IO_ >:

Protected Member Functions

 AProtocol ()=delete
 Default constructor is deleted to ensure an I/O component is always associated.
 AProtocol (_IO_ &io) noexcept
 Constructor that associates the protocol with an I/O component.
virtual ~AProtocol ()=default
 Virtual destructor.
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 onMessage (std::size_t size) noexcept=0
 Processes a complete message from the input buffer of the associated I/O component.
virtual void reset () noexcept=0
 Resets the internal parsing state of the protocol.

Protected Attributes

_IO_ & _io
 Reference to the I/O component instance that this protocol is associated with.

Additional Inherited Members

Public Member Functions inherited from qb::io::async::IProtocol
virtual ~IProtocol ()=default
 Virtual destructor.
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

template<typename _IO_>
class qb::io::async::AProtocol< _IO_ >

Abstract base class for I/O-component-aware protocols (CRTP).

This template class extends the IProtocol interface and is designed to be used with the Curiously Recurring Template Pattern (CRTP). It provides the protocol implementation with a reference (_io) to its associated I/O component (_IO_), allowing the protocol to interact with the I/O component's buffers and dispatch parsed messages to its handlers.

Template Parameters
_IO_The I/O component type (e.g., MyTcpSession) that this protocol works with. This _IO_ type is expected to provide access to input/output buffers (e.g., _io.in(), _io.out()) and an on(typename ProtocolType::message&&) handler for received messages.

Constructor & Destructor Documentation

◆ AProtocol()

template<typename _IO_>
qb::io::async::AProtocol< _IO_ >::AProtocol ( _IO_ & io)
inlineprotectednoexcept

Constructor that associates the protocol with an I/O component.

Parameters
ioReference to the I/O component (_IO_&) that will use this protocol instance.

Member Function Documentation

◆ getMessageSize()

template<typename _IO_>
virtual std::size_t qb::io::async::AProtocol< _IO_ >::getMessageSize ( )
protectedpure virtualnoexcept

Determines the size of the next complete message in the input buffer of the associated I/O component.

Returns
Size of the next complete message in bytes, or 0 if not enough data is available.

Concrete protocols must implement this to define their message framing logic by inspecting this->_io.in().

See also
IProtocol::getMessageSize()

Implements qb::io::async::IProtocol.

Implemented in 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()

template<typename _IO_>
virtual void qb::io::async::AProtocol< _IO_ >::onMessage ( std::size_t size)
protectedpure virtualnoexcept

◆ reset()