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
Buffer Module - Architecture

View-Based Buffer Design

Buffer is a lightweight VIEW over caller-owned storage. No allocation, no freeing - just state tracking: data pointer, capacity, current length.

Core API

rte_buffer_init(buf, storage, capacity); // Bind view to storage
rte_buffer_set_length(buf, new_length); // Mark data as valid
rte_buffer_clear(buf); // Reset length to 0
rte_status_t rte_buffer_set_length(rte_buffer_t *buf, size_t length)
Marks length bytes of already-written storage as valid.
Definition rte_buffer.c:31
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.
Definition rte_buffer.c:9
rte_status_t rte_buffer_clear(rte_buffer_t *buf)
Resets length to 0; capacity and data are unchanged.
Definition rte_buffer.c:21

Invariants

buf.data != NULL           - Pointing to valid storage
buf.capacity > 0           - Has space
buf.length <= buf.capacity - Never overfilled

Ownership Model

Caller owns backing storage:

  • Must allocate before rte_buffer_init()
  • Must keep valid for buffer lifetime
  • Caller manages writes to buf.data

Buffer manages:

  • Tracking length (valid data)
  • Validating length <= capacity

O(1) All Operations

Operation Time
init() O(1)
set_length() O(1)
clear() O(1)

No copying, no allocation.

See Also