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

Protocol for text messages delimited by a specific character, yielding a specified string type. More...

#include <text.h>

Inheritance diagram for qb::protocol::text::basic_text< _IO_, _StringTrait, _Sep >:
Collaboration diagram for qb::protocol::text::basic_text< _IO_, _StringTrait, _Sep >:

Classes

struct  message
 Structure representing a text message. More...

Public Member Functions

 basic_text ()=delete
 Default constructor (deleted)
 basic_text (_IO_ &io) noexcept
 Constructor with I/O reference.
void onMessage (std::size_t size) noexcept
 Process a received message.
Public Member Functions inherited from qb::protocol::base::byte_terminated< _IO_, '\0' >
 byte_terminated ()=delete
 Default constructor (deleted)
virtual ~byte_terminated ()=default
 Virtual destructor.
std::size_t shiftSize (std::size_t const size) const noexcept
 Calculates the message size without the delimiter.
std::size_t getMessageSize () noexcept final
 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.

Additional Inherited Members

Static Public Attributes inherited from qb::protocol::base::byte_terminated< _IO_, '\0' >
static constexpr const std::size_t delimiter_size
 Delimiter size (1 byte)
static constexpr const char end
 End character.
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.
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 _StringTrait, char _Sep = '\0'>
class qb::protocol::text::basic_text< _IO_, _StringTrait, _Sep >

Protocol for text messages delimited by a specific character, yielding a specified string type.

This class implements a protocol to handle text messages that are delimited by a specific character (_Sep). It uses the qb::protocol::base::byte_terminated protocol as its base and, upon receiving a complete message, provides a message struct containing the raw data, its size, and the text formatted as _StringTrait (e.g., std::string, std::string_view) to the I/O component's handler.

Template Parameters
_IO_The I/O component type that will use this protocol.
_StringTraitThe type of string to produce (e.g., std::string, std::string_view).
_SepThe delimiter character. Defaults to '\0'.

Constructor & Destructor Documentation

◆ basic_text()

template<typename _IO_, typename _StringTrait, char _Sep = '\0'>
qb::protocol::text::basic_text< _IO_, _StringTrait, _Sep >::basic_text ( _IO_ & io)
inlinenoexcept

Constructor with I/O reference.

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

Member Function Documentation

◆ onMessage()

template<typename _IO_, typename _StringTrait, char _Sep = '\0'>
void qb::protocol::text::basic_text< _IO_, _StringTrait, _Sep >::onMessage ( std::size_t size)
inlinevirtualnoexcept

Process a received message.

This method is called when a complete message is received. It builds a message object and passes it to the I/O object.

Parameters
sizeMessage size with the delimiter

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