|
nros C API
Lightweight ROS 2 client for embedded real-time systems
|
CDR serialization helpers. More...
#include "nros/types.h"

Go to the source code of this file.
Functions | |
| int32_t | nros_cdr_read_bool (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, bool *value) |
| Read a boolean value from the buffer. | |
| int32_t | nros_cdr_read_f32 (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, float *value) |
| Read a f32 value from the buffer. | |
| int32_t | nros_cdr_read_f64 (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, double *value) |
| Read a f64 value from the buffer. | |
| int32_t | nros_cdr_read_i16 (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, int16_t *value) |
| Read an i16 value from the buffer. | |
| int32_t | nros_cdr_read_i32 (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, int32_t *value) |
| Read an i32 value from the buffer. | |
| int32_t | nros_cdr_read_i64 (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, int64_t *value) |
| Read an i64 value from the buffer. | |
| int32_t | nros_cdr_read_i8 (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, int8_t *value) |
| Read an i8 value from the buffer. | |
| int32_t | nros_cdr_read_string (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, char *value, size_t max_len) |
| Read a string from the buffer into a fixed-size buffer. | |
| int32_t | nros_cdr_read_u16 (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, uint16_t *value) |
| Read a u16 value from the buffer (with alignment). | |
| int32_t | nros_cdr_read_u32 (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, uint32_t *value) |
| Read a u32 value from the buffer (with alignment). | |
| int32_t | nros_cdr_read_u64 (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, uint64_t *value) |
| Read a u64 value from the buffer (with alignment). | |
| int32_t | nros_cdr_read_u8 (const uint8_t **ptr, const uint8_t *end, const uint8_t *origin, uint8_t *value) |
| Read a u8 value from the buffer. | |
| int32_t | nros_cdr_write_bool (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, bool value) |
| Write a boolean value to the buffer. | |
| int32_t | nros_cdr_write_f32 (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, float value) |
| Write a f32 value to the buffer (with alignment). | |
| int32_t | nros_cdr_write_f64 (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, double value) |
| Write a f64 value to the buffer (with alignment). | |
| int32_t | nros_cdr_write_i16 (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, int16_t value) |
| Write an i16 value to the buffer. | |
| int32_t | nros_cdr_write_i32 (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, int32_t value) |
| Write an i32 value to the buffer. | |
| int32_t | nros_cdr_write_i64 (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, int64_t value) |
| Write an i64 value to the buffer. | |
| int32_t | nros_cdr_write_i8 (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, int8_t value) |
| Write an i8 value to the buffer. | |
| int32_t | nros_cdr_write_string (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, const char *value) |
| Write a string to the buffer (length-prefixed). | |
| int32_t | nros_cdr_write_string_n (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, const char *data, size_t len) |
| Write a string from a pointer+length pair (not null-terminated). | |
| int32_t | nros_cdr_write_u16 (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, uint16_t value) |
| Write a u16 value to the buffer (with alignment). | |
| int32_t | nros_cdr_write_u32 (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, uint32_t value) |
| Write a u32 value to the buffer (with alignment). | |
| int32_t | nros_cdr_write_u64 (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, uint64_t value) |
| Write a u64 value to the buffer (with alignment). | |
| int32_t | nros_cdr_write_u8 (uint8_t **ptr, const uint8_t *end, const uint8_t *origin, uint8_t value) |
| Write a u8 value to the buffer. | |
CDR serialization helpers.
Low-level read/write functions for CDR (Common Data Representation) encoding. These are used by generated message code and can also be called directly for manual serialization.
All functions advance the ptr cursor. They return 0 on success or a negative value if the buffer is too small.
| int32_t nros_cdr_read_bool | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| bool * | value | ||
| ) |
Read a boolean value from the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output: the value read. |
| int32_t nros_cdr_read_f32 | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| float * | value | ||
| ) |
Read a f32 value from the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output: the value read. |
| int32_t nros_cdr_read_f64 | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| double * | value | ||
| ) |
Read a f64 value from the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output: the value read. |
| int32_t nros_cdr_read_i16 | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| int16_t * | value | ||
| ) |
Read an i16 value from the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output: the value read. |
| int32_t nros_cdr_read_i32 | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| int32_t * | value | ||
| ) |
Read an i32 value from the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output: the value read. |
| int32_t nros_cdr_read_i64 | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| int64_t * | value | ||
| ) |
Read an i64 value from the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output: the value read. |
| int32_t nros_cdr_read_i8 | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| int8_t * | value | ||
| ) |
Read an i8 value from the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output: the value read. |
| int32_t nros_cdr_read_string | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| char * | value, | ||
| size_t | max_len | ||
| ) |
Read a string from the buffer into a fixed-size buffer.
CDR strings are encoded as: u32 length (including null terminator)
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output buffer for the string. |
| max_len | Maximum length of the output buffer. |
| int32_t nros_cdr_read_u16 | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| uint16_t * | value | ||
| ) |
Read a u16 value from the buffer (with alignment).
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output: the value read. |
| int32_t nros_cdr_read_u32 | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| uint32_t * | value | ||
| ) |
Read a u32 value from the buffer (with alignment).
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output: the value read. |
| int32_t nros_cdr_read_u64 | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| uint64_t * | value | ||
| ) |
Read a u64 value from the buffer (with alignment).
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output: the value read. |
| int32_t nros_cdr_read_u8 | ( | const uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| uint8_t * | value | ||
| ) |
Read a u8 value from the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Output: the value read. |
| int32_t nros_cdr_write_bool | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| bool | value | ||
| ) |
Write a boolean value to the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Boolean value to write. |
| int32_t nros_cdr_write_f32 | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| float | value | ||
| ) |
Write a f32 value to the buffer (with alignment).
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Value to write. |
| int32_t nros_cdr_write_f64 | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| double | value | ||
| ) |
Write a f64 value to the buffer (with alignment).
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Value to write. |
| int32_t nros_cdr_write_i16 | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| int16_t | value | ||
| ) |
Write an i16 value to the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Value to write. |
| int32_t nros_cdr_write_i32 | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| int32_t | value | ||
| ) |
Write an i32 value to the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Value to write. |
| int32_t nros_cdr_write_i64 | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| int64_t | value | ||
| ) |
Write an i64 value to the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Value to write. |
| int32_t nros_cdr_write_i8 | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| int8_t | value | ||
| ) |
Write an i8 value to the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Value to write. |
| int32_t nros_cdr_write_string | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| const char * | value | ||
| ) |
Write a string to the buffer (length-prefixed).
CDR strings are encoded as: u32 length (including null terminator)
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Null-terminated string to write. |
| int32_t nros_cdr_write_string_n | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| const char * | data, | ||
| size_t | len | ||
| ) |
Write a string from a pointer+length pair (not null-terminated).
Used by borrowed message types where the string field is a struct { const char* data; size_t size; } rather than a char[].
CDR encoding: u32 length (size + 1 for null) + bytes + null terminator.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| data | String data (may not be null-terminated). |
| len | String length in bytes (excluding any null terminator). |
| int32_t nros_cdr_write_u16 | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| uint16_t | value | ||
| ) |
Write a u16 value to the buffer (with alignment).
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Value to write. |
| int32_t nros_cdr_write_u32 | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| uint32_t | value | ||
| ) |
Write a u32 value to the buffer (with alignment).
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Value to write. |
| int32_t nros_cdr_write_u64 | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| uint64_t | value | ||
| ) |
Write a u64 value to the buffer (with alignment).
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Value to write. |
| int32_t nros_cdr_write_u8 | ( | uint8_t ** | ptr, |
| const uint8_t * | end, | ||
| const uint8_t * | origin, | ||
| uint8_t | value | ||
| ) |
Write a u8 value to the buffer.
| ptr | Pointer to the cursor (advanced on success). |
| end | Pointer past the end of the buffer. |
| origin | Buffer origin (for alignment calculations). |
| value | Value to write. |