|
Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
|
Implementation of the cross-layer data buffer abstraction (ADR-002). More...
Go to the source code of this file.
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. | |
| static sapi_status_t | sapi_buffer_append_bytes (sapi_buffer_t *buf, const unsigned char *bytes, size_t n) |
| Appends n raw bytes at buf's current length, advancing it. Shared by every sapi_buffer_write_*_le/be function. | |
| static sapi_status_t | sapi_buffer_peek_bytes (const sapi_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 sapi_buffer_read_*_le/be function. | |
| 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(). | |
Implementation of the cross-layer data buffer abstraction (ADR-002).
Definition in file sapi_buffer.c.
|
static |
Appends n raw bytes at buf's current length, advancing it. Shared by every sapi_buffer_write_*_le/be function.
| buf | Destination buffer. Must not be NULL. |
| bytes | Raw bytes to append. Must not be NULL. |
| n | Number of bytes to append. |
Definition at line 123 of file sapi_buffer.c.
|
static |
Reads n raw bytes starting at offset, without mutating buf. Shared by every sapi_buffer_read_*_le/be function.
| buf | Source buffer. Must not be NULL. |
| offset | Byte offset within buf's valid bytes to read from. |
| out_bytes | Destination for the raw bytes. Must not be NULL. |
| n | Number of bytes to read. |
Definition at line 152 of file sapi_buffer.c.