BCNP 3.2.1
Batched Command Network Protocol
Loading...
Searching...
No Matches
bcnp::PacketView Struct Reference

Zero-copy view into a decoded packet buffer. More...

#include <packet.h>

Collaboration diagram for bcnp::PacketView:
[legend]

Public Member Functions

MessageTypeId GetMessageType () const
 Get the message type ID for this packet.
 
template<typename MsgType >
MessageIterator< MsgType > begin_as () const
 Get type-safe iterator to the first message.
 
template<typename MsgType >
MessageIterator< MsgType > end_as () const
 Get end iterator for type-safe message iteration.
 
const uint8_t * GetPayload () const
 Get raw pointer to payload for manual parsing.
 
std::size_t GetPayloadSize () const
 Calculate total payload size in bytes.
 

Public Attributes

PacketHeader header {}
 Parsed header information.
 
const uint8_t * payloadStart {nullptr}
 Pointer to first message in buffer.
 

Detailed Description

Zero-copy view into a decoded packet buffer.

PacketView provides read-only access to a validated packet without copying the message data. Use begin_as<T>/end_as<T> to iterate over messages with type checking, or GetPayload() for raw access.

Note
The view is only valid while the underlying buffer exists. Do not store views beyond the lifetime of the source buffer.

Definition at line 170 of file packet.h.

Member Function Documentation

◆ begin_as()

template<typename MsgType >
MessageIterator< MsgType > bcnp::PacketView::begin_as ( ) const
inline

Get type-safe iterator to the first message.

Returns an empty iterator if MsgType::kTypeId doesn't match the packet's message type, providing compile-time type safety with runtime validation.

Template Parameters
MsgTypeThe expected message type
Returns
Iterator to first message, or end iterator on type mismatch

Definition at line 190 of file packet.h.

◆ end_as()

template<typename MsgType >
MessageIterator< MsgType > bcnp::PacketView::end_as ( ) const
inline

Get end iterator for type-safe message iteration.

Template Parameters
MsgTypeThe message type (must match begin_as call)
Returns
End sentinel iterator

Definition at line 203 of file packet.h.

◆ GetMessageType()

MessageTypeId bcnp::PacketView::GetMessageType ( ) const
inline

Get the message type ID for this packet.

Returns
The MessageTypeId from the header

Definition at line 178 of file packet.h.

◆ GetPayload()

const uint8_t * bcnp::PacketView::GetPayload ( ) const
inline

Get raw pointer to payload for manual parsing.

Returns
Pointer to first byte after header

Definition at line 211 of file packet.h.

◆ GetPayloadSize()

std::size_t bcnp::PacketView::GetPayloadSize ( ) const

Calculate total payload size in bytes.

Returns
messageCount * wireSize for the message type

Definition at line 58 of file packet.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ header

PacketHeader bcnp::PacketView::header {}

Parsed header information.

Definition at line 171 of file packet.h.

◆ payloadStart

const uint8_t* bcnp::PacketView::payloadStart {nullptr}

Pointer to first message in buffer.

Definition at line 172 of file packet.h.


The documentation for this struct was generated from the following files: