UNISTDX_FUNC
UNISTDX_BASE_PACKETBUF
using packetbuf = basic_packetbuf< char >

Alias to basic_packetbuf<char>.

template <class Ch, class Tr = std::char_traits<Ch>>
class sys::basic_packetbuf

Stream buffer that can reads/writes data in packets with arbitrary header.

  • By default header size is nought, and packet buffer works as a regular stream buffer.

Base classes
  • public virtual std::basic_streambuf< Ch, std::char_traits< Ch > >
Types
Fields
  • const char * _name

    Packet buffer name for debugging.

Methods
  • set_ipacket(off_type pos1, off_type pos2, std::streamsize n) -> voidprotected

    Set incoming packet offset to pos1, payload offset to pos2 and size to n.

  • set_opacket(off_type pos1) -> voidprotected

    Set outgoing packet offset relative to pbase.

  • set_oheader(std::streamsize size) -> voidprotected

    Set outgoing packet header size.

  • oheadersize() const -> std::streamsizeprotected

    Get outgoing packet header size.

  • opacketsize() const -> std::streamsizeprotected

    The size of the outgoing packet in bytes.

  • opacketpos() const -> off_typeprotected

    Offset of the first outgoing packet byte relative to pbase.

  • opacket_end() const -> char_type *protected

    Pointer to the end of the outgoing packet.

  • opacket_begin() const -> char_type *protected

    Pointer to the beginning of the outgoing packet.

  • ipacketpos() const -> off_typeprotected

    Offset of the first incoming packet byte relative to eback.

  • ipayloadpos() const -> off_typeprotected

    Offset of the first incoming packet payload byte relative to eback.

  • state() const -> state_typeprotected

    Packet parsing state.

  • on_payload() -> voidprotectedvirtual

    This function is called when payload becomes ready. Does nothing by default.

  • xgetheader(UNISTDX_UNUSED std::streamsize & header_size, std::streamsize & payload_size) -> boolprotectedvirtual

    Read packet header and return header and payload size.

    header_size
    the size of packet header

    payload_size
    the size of packet payload

    Return
    true, if there are enough bytes to parse the header
  • overwrite_header(std::streamsize) -> std::streamsizeprotectedvirtual

    Overwrite packet header when actual packet size is known. The argument is packet size.

    Return
    header size
  • put_header() -> voidprotectedvirtual

    Write packet header into the put buffer. Does nothing by default. The method is called in begin_packet to write intiial packet header when actual packet size is not known.

  • seek_ipayloadpos(off_type off) -> void

    Seeks get buffer position from the beginning of input packet payload.

  • ipayloadsize() const -> std::streamsize

    Returns the size of the incoming packet payload.

  • ipayload_end() const -> const char_type *

    Returns the pointer to the end of incoming packet payload.

  • ipayload_end() -> char_type *

    Returns the pointer to the end of incoming packet payload.

  • ipayload_cur() const -> const char_type *

    Returns the pointer to the current byte of incoming packet payload.

  • ipayload_cur() -> char_type *

    Returns the pointer to the current byte of incoming packet payload.

  • ipayload_begin() const -> const char_type *

    Returns the pointer to the beginning of incoming packet payload.

  • ipayload_begin() -> char_type *

    Returns the pointer to the beginning of incoming packet payload.

  • ipacketsize() const -> std::streamsize

    The size of the incoming packet.

  • ipacket_end() const -> const char_type *

    Returns the pointer to the end of incoming packet.

  • ipacket_end() -> char_type *

    Returns the pointer to the end of incoming packet.

  • ipacket_begin() const -> const char_type *

    Returns the pointer to the beginning of incoming packet.

  • ipacket_begin() -> char_type *

    Returns the pointer to the beginning of incoming packet.

  • is_safe_to_compact() const -> bool

    Returns true if packet buffer can be compacted without ruining the state which might have been save by subclasses.

  • set_name(const char * rhs) -> void

    Set packet buffer name for debugging.

  • ipayload_offset() const -> std::streamsize

    Get pointer offset within the payload.

  • available() const -> std::streamsize

    Returns the number of available bytes in get buffer.

  • remaining() const -> std::streamsize

    Returns the number of remaining bytes in put buffer.

  • dirty() const -> bool

    Returns true, if put buffer is non-empty.

  • skip_packet() -> void

    Move to the next input packet, if the payload of the current packet is ready.

  • read_packet() -> bool

    Read the packet and update packet parsing state.

  • cancel_packet() -> void

    Cancel writing a packet, resetting put buffer position.

  • end_packet() -> void

    Finish writing the packet by updating its header with actual packet size.

  • begin_packet() -> void

    Start writing a packet by appending an empty header.

  • handshake() -> boolvirtual

    Perform protocol-specific handshake. Does nothing by default.

    Return
    true, if handshake was successful.
  • ~basic_packetbuf()virtual
  • basic_packetbuf()
Friends
  • template <class Ch1, class Tr1>
    append_payload

    Append full payload of the packet from dest to src. Only payload is copied.

  • template <class Ch2, class Tr2>
    basic_ipacket_guard
template <class Ch, class Tr>
class sys::basic_ipacket_guard

Guard object that preserves packet buffer state upon failure.

Types
  • using streambuf_type = basic_packetbuf< Ch, Tr >

    Stream buffer type.

  • using char_type = Ch

    Character type.

Methods
  • ~basic_ipacket_guard()

    Destroy incoming packet guard, restore buffer state and skip remaining payload bytes (if any).

  • basic_ipacket_guard(streambuf_type * buf)explicit

    Construct incoming packet guard for packet buffer buf, save buffer state and set get buffer pointers to limit reading only to payload part of the packet buffer.

template <class Ch>
struct sys::streamptr

Object that stores streambuf internal state.

Types
  • using char_type = Ch

    Character type.

Fields
  • char_type * _egptr

    Pointer to the end of get area.

  • char_type * _gptr

    Pointer to the current character of get area.

  • char_type * _eback

    Pointer to the beginning of get area.

template <class Ch, class Tr>
append_payload(basic_packetbuf< Ch, Tr > & dest, basic_packetbuf< Ch, Tr > & src, std::streamsize off = 0) -> void

Append full payload of the packet from dest to src. Only payload is copied.