nros C API
Lightweight ROS 2 client for embedded real-time systems
Loading...
Searching...
No Matches
Functions
cdr.h File Reference

CDR serialization helpers. More...

#include "nros/types.h"
Include dependency graph for cdr.h:
This graph shows which files directly or indirectly include this file:

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.
 

Detailed Description

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.

Function Documentation

◆ nros_cdr_read_bool()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput: the value read.
Returns
0 on success, negative on overflow.

◆ nros_cdr_read_f32()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput: the value read.
Returns
0 on success, negative on overflow.

◆ nros_cdr_read_f64()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput: the value read.
Returns
0 on success, negative on overflow.

◆ nros_cdr_read_i16()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput: the value read.
Returns
0 on success, negative on overflow.

◆ nros_cdr_read_i32()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput: the value read.
Returns
0 on success, negative on overflow.

◆ nros_cdr_read_i64()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput: the value read.
Returns
0 on success, negative on overflow.

◆ nros_cdr_read_i8()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput: the value read.
Returns
0 on success, negative on overflow.

◆ nros_cdr_read_string()

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)

  • bytes + null terminator.
Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput buffer for the string.
max_lenMaximum length of the output buffer.
Returns
0 on success, negative on overflow or truncation.

◆ nros_cdr_read_u16()

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).

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput: the value read.
Returns
0 on success, negative on overflow.

◆ nros_cdr_read_u32()

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).

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput: the value read.
Returns
0 on success, negative on overflow.

◆ nros_cdr_read_u64()

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).

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput: the value read.
Returns
0 on success, negative on overflow.

◆ nros_cdr_read_u8()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueOutput: the value read.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_bool()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueBoolean value to write.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_f32()

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).

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueValue to write.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_f64()

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).

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueValue to write.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_i16()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueValue to write.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_i32()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueValue to write.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_i64()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueValue to write.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_i8()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueValue to write.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_string()

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)

  • bytes + null terminator.
Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueNull-terminated string to write.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_string_n()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
dataString data (may not be null-terminated).
lenString length in bytes (excluding any null terminator).
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_u16()

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).

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueValue to write.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_u32()

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).

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueValue to write.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_u64()

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).

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueValue to write.
Returns
0 on success, negative on overflow.

◆ nros_cdr_write_u8()

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.

Parameters
ptrPointer to the cursor (advanced on success).
endPointer past the end of the buffer.
originBuffer origin (for alignment calculations).
valueValue to write.
Returns
0 on success, negative on overflow.