|
Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
|
Caller-owned, bounds-checked view over static storage (ADR-002). More...
Files | |
| file | src/utils/buffer/sapi_buffer.c |
| Implementation of the cross-layer data buffer abstraction (ADR-002). | |
Data Structures | |
| struct | sapi_buffer_t |
| Mutable, bounds-tracked view over caller-owned storage. More... | |
| struct | sapi_const_buffer_t |
| Read-only view of a buffer's currently valid bytes. Grants no write access to the underlying storage. More... | |
Functions | |
| sapi_status_t | sapi_buffer_init (sapi_buffer_t *buf, void *storage, size_t capacity) |
| Binds a buffer view to caller-owned storage. Initial length is 0. | |
| sapi_status_t | sapi_buffer_clear (sapi_buffer_t *buf) |
| Resets length to 0; capacity and data are unchanged. | |
| sapi_status_t | sapi_buffer_set_length (sapi_buffer_t *buf, size_t length) |
| Marks length bytes of already-written storage as valid. | |
| sapi_status_t | sapi_buffer_copy_in (sapi_buffer_t *buf, const void *src, size_t src_len) |
| Bounds-checked copy of external data into the buffer; sets length. | |
| sapi_status_t | sapi_buffer_copy_out (const sapi_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. | |
| sapi_status_t | sapi_buffer_as_const (const sapi_buffer_t *buf, sapi_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 | sapi_buffer_is_valid (const sapi_buffer_t *buf) |
| Defensive validity check: non-null data and length <= capacity. | |
| sapi_status_t | sapi_buffer_write_u16_le (sapi_buffer_t *buf, uint16_t value) |
| Appends a little-endian uint16_t at buf's current length. | |
| sapi_status_t | sapi_buffer_write_u16_be (sapi_buffer_t *buf, uint16_t value) |
| Appends a big-endian uint16_t. See sapi_buffer_write_u16_le(). | |
| sapi_status_t | sapi_buffer_write_u32_le (sapi_buffer_t *buf, uint32_t value) |
| Appends a little-endian uint32_t at buf's current length. | |
| sapi_status_t | sapi_buffer_write_u32_be (sapi_buffer_t *buf, uint32_t value) |
| Appends a big-endian uint32_t. See sapi_buffer_write_u32_le(). | |
| sapi_status_t | sapi_buffer_write_u64_le (sapi_buffer_t *buf, uint64_t value) |
| Appends a little-endian uint64_t at buf's current length. | |
| sapi_status_t | sapi_buffer_write_u64_be (sapi_buffer_t *buf, uint64_t value) |
| Appends a big-endian uint64_t. See sapi_buffer_write_u64_le(). | |
| sapi_status_t | sapi_buffer_read_u16_le (const sapi_buffer_t *buf, size_t offset, uint16_t *out_value) |
| Reads a little-endian uint16_t at the given offset. | |
| sapi_status_t | sapi_buffer_read_u16_be (const sapi_buffer_t *buf, size_t offset, uint16_t *out_value) |
| Reads a big-endian uint16_t. See sapi_buffer_read_u16_le(). | |
| sapi_status_t | sapi_buffer_read_u32_le (const sapi_buffer_t *buf, size_t offset, uint32_t *out_value) |
| Reads a little-endian uint32_t at the given offset. | |
| sapi_status_t | sapi_buffer_read_u32_be (const sapi_buffer_t *buf, size_t offset, uint32_t *out_value) |
| Reads a big-endian uint32_t. See sapi_buffer_read_u32_le(). | |
| sapi_status_t | sapi_buffer_read_u64_le (const sapi_buffer_t *buf, size_t offset, uint64_t *out_value) |
| Reads a little-endian uint64_t at the given offset. | |
| sapi_status_t | sapi_buffer_read_u64_be (const sapi_buffer_t *buf, size_t offset, uint64_t *out_value) |
| Reads a big-endian uint64_t. See sapi_buffer_read_u64_le(). | |
Caller-owned, bounds-checked view over static storage (ADR-002).
| sapi_status_t sapi_buffer_init | ( | sapi_buffer_t * | buf, |
| void * | storage, | ||
| size_t | capacity ) |
Binds a buffer view to caller-owned storage. Initial length is 0.
| buf | Buffer view to initialize. Must not be NULL. |
| storage | Caller-owned backing storage. Must not be NULL and must remain valid for the lifetime of buf. |
| capacity | Usable size of storage in bytes. Must be > 0. |
Definition at line 9 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_clear | ( | sapi_buffer_t * | buf | ) |
Resets length to 0; capacity and data are unchanged.
| buf | Buffer to clear. Must not be NULL and must satisfy sapi_buffer_is_valid(). |
Definition at line 21 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_set_length | ( | sapi_buffer_t * | buf, |
| size_t | length ) |
Marks length bytes of already-written storage as valid.
| buf | Buffer to update. Must not be NULL. |
| length | New valid length in bytes. |
Definition at line 31 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_copy_in | ( | sapi_buffer_t * | buf, |
| const void * | src, | ||
| size_t | src_len ) |
Bounds-checked copy of external data into the buffer; sets length.
| buf | Destination buffer. Must not be NULL. |
| src | Source data to copy in. Must not be NULL. |
| src_len | Number of bytes to copy from src. |
Definition at line 45 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_copy_out | ( | const sapi_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.
| buf | Source buffer. Must not be NULL. |
| dest | Destination to copy into. Must not be NULL. |
| dest_capacity | Usable size of dest in bytes. |
| out_copied | Receives the number of bytes actually copied (== buf->length on success; 0 on failure). Must not be NULL. |
Definition at line 63 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_as_const | ( | const sapi_buffer_t * | buf, |
| sapi_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.
| buf | Source buffer. Must not be NULL. |
| out_view | Receives the read-only view. Must not be NULL. |
Definition at line 85 of file sapi_buffer.c.
| bool sapi_buffer_is_valid | ( | const sapi_buffer_t * | buf | ) |
Defensive validity check: non-null data and length <= capacity.
| buf | Buffer to check; NULL is a valid input (returns false). |
Definition at line 100 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_write_u16_le | ( | sapi_buffer_t * | buf, |
| uint16_t | value ) |
Appends a little-endian uint16_t at buf's current length.
| buf | Destination buffer. Must not be NULL. |
| value | Value to encode and append. |
Definition at line 170 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_write_u16_be | ( | sapi_buffer_t * | buf, |
| uint16_t | value ) |
Appends a big-endian uint16_t. See sapi_buffer_write_u16_le().
| buf | Destination buffer. Must not be NULL. |
| value | Value to encode and append. |
Definition at line 178 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_write_u32_le | ( | sapi_buffer_t * | buf, |
| uint32_t | value ) |
Appends a little-endian uint32_t at buf's current length.
| buf | Destination buffer. Must not be NULL. |
| value | Value to encode and append. |
Definition at line 186 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_write_u32_be | ( | sapi_buffer_t * | buf, |
| uint32_t | value ) |
Appends a big-endian uint32_t. See sapi_buffer_write_u32_le().
| buf | Destination buffer. Must not be NULL. |
| value | Value to encode and append. |
Definition at line 196 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_write_u64_le | ( | sapi_buffer_t * | buf, |
| uint64_t | value ) |
Appends a little-endian uint64_t at buf's current length.
| buf | Destination buffer. Must not be NULL. |
| value | Value to encode and append. |
Definition at line 206 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_write_u64_be | ( | sapi_buffer_t * | buf, |
| uint64_t | value ) |
Appends a big-endian uint64_t. See sapi_buffer_write_u64_le().
| buf | Destination buffer. Must not be NULL. |
| value | Value to encode and append. |
Definition at line 217 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_read_u16_le | ( | const sapi_buffer_t * | buf, |
| size_t | offset, | ||
| uint16_t * | out_value ) |
Reads a little-endian uint16_t at the given offset.
| buf | Source buffer. Must not be NULL. |
| offset | Byte offset within buf's valid bytes to read from. |
| out_value | Receives the decoded value. Must not be NULL. |
Definition at line 229 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_read_u16_be | ( | const sapi_buffer_t * | buf, |
| size_t | offset, | ||
| uint16_t * | out_value ) |
Reads a big-endian uint16_t. See sapi_buffer_read_u16_le().
| buf | Source buffer. Must not be NULL. |
| offset | Byte offset within buf's valid bytes to read from. |
| out_value | Receives the decoded value. Must not be NULL. |
Definition at line 249 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_read_u32_le | ( | const sapi_buffer_t * | buf, |
| size_t | offset, | ||
| uint32_t * | out_value ) |
Reads a little-endian uint32_t at the given offset.
| buf | Source buffer. Must not be NULL. |
| offset | Byte offset within buf's valid bytes to read from. |
| out_value | Receives the decoded value. Must not be NULL. |
Definition at line 269 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_read_u32_be | ( | const sapi_buffer_t * | buf, |
| size_t | offset, | ||
| uint32_t * | out_value ) |
Reads a big-endian uint32_t. See sapi_buffer_read_u32_le().
| buf | Source buffer. Must not be NULL. |
| offset | Byte offset within buf's valid bytes to read from. |
| out_value | Receives the decoded value. Must not be NULL. |
Definition at line 290 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_read_u64_le | ( | const sapi_buffer_t * | buf, |
| size_t | offset, | ||
| uint64_t * | out_value ) |
Reads a little-endian uint64_t at the given offset.
| buf | Source buffer. Must not be NULL. |
| offset | Byte offset within buf's valid bytes to read from. |
| out_value | Receives the decoded value. Must not be NULL. |
Definition at line 311 of file sapi_buffer.c.
| sapi_status_t sapi_buffer_read_u64_be | ( | const sapi_buffer_t * | buf, |
| size_t | offset, | ||
| uint64_t * | out_value ) |
Reads a big-endian uint64_t. See sapi_buffer_read_u64_le().
| buf | Source buffer. Must not be NULL. |
| offset | Byte offset within buf's valid bytes to read from. |
| out_value | Receives the decoded value. Must not be NULL. |
Definition at line 335 of file sapi_buffer.c.