Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
rte_buffer.c File Reference

Implementation of the cross-layer data buffer abstraction (ADR-002). More...

#include "rte/utils/buffer/rte_buffer.h"
#include <string.h>
Include dependency graph for rte_buffer.c:

Go to the source code of this file.

Functions

rte_status_t rte_buffer_init (rte_buffer_t *buf, void *storage, size_t capacity)
 Binds a buffer view to caller-owned storage. Initial length is 0.
rte_status_t rte_buffer_clear (rte_buffer_t *buf)
 Resets length to 0; capacity and data are unchanged.
rte_status_t rte_buffer_set_length (rte_buffer_t *buf, size_t length)
 Marks length bytes of already-written storage as valid.
rte_status_t rte_buffer_copy_in (rte_buffer_t *buf, const void *src, size_t src_len)
 Bounds-checked copy of external data into the buffer; sets length.
rte_status_t rte_buffer_copy_out (const rte_buffer_t *buf, void *dest, size_t dest_capacity, size_t *out_copied)
 Bounds-checked copy of the buffer's valid bytes to an external destination.
rte_status_t rte_buffer_as_const (const rte_buffer_t *buf, rte_const_buffer_t *out_view)
 Produces a read-only view of the buffer's current valid bytes. The view is only valid as long as the source buffer's storage is.
bool rte_buffer_is_valid (const rte_buffer_t *buf)
 Defensive validity check: non-null data and length <= capacity.
static rte_status_t rte_buffer_append_bytes (rte_buffer_t *buf, const unsigned char *bytes, size_t n)
 Appends n raw bytes at buf's current length, advancing it. Shared by every rte_buffer_write_*_le/be function.
static rte_status_t rte_buffer_peek_bytes (const rte_buffer_t *buf, size_t offset, unsigned char *out_bytes, size_t n)
 Reads n raw bytes starting at offset, without mutating buf. Shared by every rte_buffer_read_*_le/be function.
rte_status_t rte_buffer_write_u16_le (rte_buffer_t *buf, uint16_t value)
 Appends a little-endian uint16_t at buf's current length.
rte_status_t rte_buffer_write_u16_be (rte_buffer_t *buf, uint16_t value)
 Appends a big-endian uint16_t. See rte_buffer_write_u16_le().
rte_status_t rte_buffer_write_u32_le (rte_buffer_t *buf, uint32_t value)
 Appends a little-endian uint32_t at buf's current length.
rte_status_t rte_buffer_write_u32_be (rte_buffer_t *buf, uint32_t value)
 Appends a big-endian uint32_t. See rte_buffer_write_u32_le().
rte_status_t rte_buffer_write_u64_le (rte_buffer_t *buf, uint64_t value)
 Appends a little-endian uint64_t at buf's current length.
rte_status_t rte_buffer_write_u64_be (rte_buffer_t *buf, uint64_t value)
 Appends a big-endian uint64_t. See rte_buffer_write_u64_le().
rte_status_t rte_buffer_read_u16_le (const rte_buffer_t *buf, size_t offset, uint16_t *out_value)
 Reads a little-endian uint16_t at the given offset.
rte_status_t rte_buffer_read_u16_be (const rte_buffer_t *buf, size_t offset, uint16_t *out_value)
 Reads a big-endian uint16_t. See rte_buffer_read_u16_le().
rte_status_t rte_buffer_read_u32_le (const rte_buffer_t *buf, size_t offset, uint32_t *out_value)
 Reads a little-endian uint32_t at the given offset.
rte_status_t rte_buffer_read_u32_be (const rte_buffer_t *buf, size_t offset, uint32_t *out_value)
 Reads a big-endian uint32_t. See rte_buffer_read_u32_le().
rte_status_t rte_buffer_read_u64_le (const rte_buffer_t *buf, size_t offset, uint64_t *out_value)
 Reads a little-endian uint64_t at the given offset.
rte_status_t rte_buffer_read_u64_be (const rte_buffer_t *buf, size_t offset, uint64_t *out_value)
 Reads a big-endian uint64_t. See rte_buffer_read_u64_le().

Detailed Description

Implementation of the cross-layer data buffer abstraction (ADR-002).

Definition in file rte_buffer.c.

Function Documentation

◆ rte_buffer_append_bytes()

rte_status_t rte_buffer_append_bytes ( rte_buffer_t * buf,
const unsigned char * bytes,
size_t n )
static

Appends n raw bytes at buf's current length, advancing it. Shared by every rte_buffer_write_*_le/be function.

Parameters
bufDestination buffer. Must not be NULL.
bytesRaw bytes to append. Must not be NULL.
nNumber of bytes to append.
Returns
RTE_STATUS_OK on success; RTE_STATUS_INVALID_PARAM if buf or bytes is NULL or buf fails its validity check; RTE_STATUS_RESOURCE_EXHAUSTED if n bytes will not fit.

Definition at line 123 of file rte_buffer.c.

◆ rte_buffer_peek_bytes()

rte_status_t rte_buffer_peek_bytes ( const rte_buffer_t * buf,
size_t offset,
unsigned char * out_bytes,
size_t n )
static

Reads n raw bytes starting at offset, without mutating buf. Shared by every rte_buffer_read_*_le/be function.

Parameters
bufSource buffer. Must not be NULL.
offsetByte offset within buf's valid bytes to read from.
out_bytesDestination for the raw bytes. Must not be NULL.
nNumber of bytes to read.
Returns
RTE_STATUS_OK on success; RTE_STATUS_INVALID_PARAM for a NULL pointer; RTE_STATUS_RESOURCE_EXHAUSTED if offset+n exceeds buf->length.

Definition at line 152 of file rte_buffer.c.