qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::protocol::base::bytes_terminated< _IO_, _Trait > Class Template Reference

Protocol for messages delimited by a specific sequence of bytes (a string literal). More...

#include <base.h>

Inheritance diagram for qb::protocol::base::bytes_terminated< _IO_, _Trait >:
Collaboration diagram for qb::protocol::base::bytes_terminated< _IO_, _Trait >:

Public Member Functions

 bytes_terminated ()=delete
 Default constructor (deleted)
virtual ~bytes_terminated ()=default
 Virtual destructor.
 bytes_terminated (_IO_ &io) noexcept
 Constructor with I/O reference.
std::size_t shiftSize (std::size_t const size) const noexcept
 Calculates the message size without the delimiter.
std::size_t getMessageSize ()
 Determines the size of the next complete message.
void reset () noexcept final
 Resets the protocol state.
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.

Static Public Attributes

static constexpr const std::size_t delimiter_size
 Delimiter size.
static constexpr const auto end = _Trait::_EndBytes
 End sequence.

Additional Inherited Members

Protected Member Functions inherited from qb::io::async::AProtocol< _IO_ >
 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 void onMessage (std::size_t size) noexcept=0
 Processes a complete message from the input buffer of the associated I/O component.
Protected Attributes inherited from qb::io::async::AProtocol< _IO_ >
_IO_ & _io
 Reference to the I/O component instance that this protocol is associated with.

Detailed Description

template<typename _IO_, typename _Trait>
class qb::protocol::base::bytes_terminated< _IO_, _Trait >

Protocol for messages delimited by a specific sequence of bytes (a string literal).

This class implements a protocol where messages are framed by a specific sequence of bytes, defined via a trait struct providing the _EndBytes sequence. For example, it can be used for HTTP-like messages ending in "\r\n\r\n". It inherits from qb::io::async::AProtocol.

Template Parameters
_IO_The I/O component type that will use this protocol. It needs to provide an in() method for input buffer access.
_TraitA trait class that must define a static constexpr char array _EndBytes representing the termination sequence (e.g., struct CRLF { static constexpr char _EndBytes[] = "\r\n"; };).

Constructor & Destructor Documentation

◆ bytes_terminated()

template<typename _IO_, typename _Trait>
qb::protocol::base::bytes_terminated< _IO_, _Trait >::bytes_terminated ( _IO_ & io)
inlinenoexcept

Constructor with I/O reference.

Parameters
ioReference to the I/O object that uses this protocol

Member Function Documentation

◆ shiftSize()

template<typename _IO_, typename _Trait>
std::size_t qb::protocol::base::bytes_terminated< _IO_, _Trait >::shiftSize ( std::size_t const size) const
inlinenoexcept

Calculates the message size without the delimiter.

Parameters
sizeTotal size including the delimiter
Returns
Message size without the delimiter

◆ getMessageSize()

template<typename _IO_, typename _Trait>
std::size_t qb::protocol::base::bytes_terminated< _IO_, _Trait >::getMessageSize ( )
inlinevirtual

Determines the size of the next complete message.

Searches for the termination sequence in the input buffer.

Returns
Message size if found, 0 otherwise

Implements qb::io::async::AProtocol< _IO_ >.

◆ reset()

template<typename _IO_, typename _Trait>
void qb::protocol::base::bytes_terminated< _IO_, _Trait >::reset ( )
inlinefinalvirtualnoexcept

Resets the protocol state.

Implements qb::io::async::AProtocol< _IO_ >.

Member Data Documentation

◆ delimiter_size

template<typename _IO_, typename _Trait>
const std::size_t qb::protocol::base::bytes_terminated< _IO_, _Trait >::delimiter_size
staticconstexpr
Initial value:
=
_SizeBytes

Delimiter size.