YAPB
Loading...
Searching...
No Matches
Query Operations

Functions

YAPB_Result_t YAPB_get_error (const YAPB_Packet_t *pkt)
 Get the sticky error state of a packet.
YAPB_Result_t YAPB_get_elem_count (const YAPB_Packet_t *pkt, uint16_t *out_count)
 Count the number of elements in a packet.
const char * YAPB_Result_str (YAPB_Result_t result)
 Get a human-readable string for a result code.
const uint8_t * YAPB_get_buffer (const YAPB_Packet_t *pkt, size_t *out_len)
 Get a const pointer to the packet's backing buffer and its length.
bool YAPB_check_complete (const uint8_t *data, size_t len)
 Check if a receive buffer contains a complete YAPB packet.

Detailed Description

Functions to inspect packet state without modifying it.

Function Documentation

◆ YAPB_check_complete()

bool YAPB_check_complete ( const uint8_t * data,
size_t len )

Check if a receive buffer contains a complete YAPB packet.

Reads the 4-byte header to determine the expected packet length, then checks if the buffer contains at least that many bytes. Useful for framing packets from a stream (e.g., TCP socket).

Parameters
dataRaw data buffer (may be a partial packet).
lenNumber of bytes available in the buffer.
Returns
true if the buffer contains a complete packet, false otherwise.

◆ YAPB_get_buffer()

const uint8_t * YAPB_get_buffer ( const YAPB_Packet_t * pkt,
size_t * out_len )

Get a const pointer to the packet's backing buffer and its length.

In read mode, returns the buffer and the packet length from the header. In write mode, returns the buffer and its length only after YAPB_finalize() has been called; returns NULL if the packet has not been finalized.

Parameters
pktPacket to query.
out_lenOutput: packet length in bytes. May be NULL.
Returns
Pointer to the buffer, or NULL if pkt is NULL or not finalized in write mode.

◆ YAPB_get_elem_count()

YAPB_Result_t YAPB_get_elem_count ( const YAPB_Packet_t * pkt,
uint16_t * out_count )

Count the number of elements in a packet.

Scans the packet from the header without advancing the read position. Nested packets count as a single element.

Parameters
pktPacket in read mode.
out_countOutput: number of elements.
Returns
YAPB_OK on success, error code otherwise.

◆ YAPB_get_error()

YAPB_Result_t YAPB_get_error ( const YAPB_Packet_t * pkt)

Get the sticky error state of a packet.

Returns the current error state. A non-negative value means no error has occurred (YAPB_OK or YAPB_STS_COMPLETE).

Parameters
pktPacket to check.
Returns
YAPB_OK or YAPB_STS_COMPLETE if no error, negative error code otherwise.

◆ YAPB_Result_str()

const char * YAPB_Result_str ( YAPB_Result_t result)

Get a human-readable string for a result code.

Parameters
resultResult code.
Returns
Static string description (never NULL).