File syn_cbor_read.c¶
FileList > src > syntropic > util > syn_cbor_read.c
Go to the source code of this file
CBOR decoder implementation.
#include "syn_cbor_read.h"#include <string.h>
Public Functions¶
| Type | Name |
|---|---|
| SYN_CborType | syn_cbor_peek_type (const SYN_CborReader * r) Return the type of the next item without consuming it. |
| size_t | syn_cbor_read_array_begin (SYN_CborReader * r) Consume an array header; return the number of items. |
| bool | syn_cbor_read_bool (SYN_CborReader * r) Read a boolean (major type 7, info 20 or 21). |
| size_t | syn_cbor_read_bytes (SYN_CborReader * r, uint8_t * buf, size_t cap) Read a byte string into a caller-provided buffer. |
| float | syn_cbor_read_float (SYN_CborReader * r) Read a float32 value (major type 7, info=26). |
| int64_t | syn_cbor_read_int (SYN_CborReader * r) Read a signed integer (major type 0 or 1). |
| size_t | syn_cbor_read_map_begin (SYN_CborReader * r) Consume a map header; return the number of key-value pairs. |
| void | syn_cbor_read_null (SYN_CborReader * r) Consume a null item (major type 7, info=22). |
| size_t | syn_cbor_read_text (SYN_CborReader * r, char * buf, size_t cap) Read a text string into a caller-provided buffer. |
| uint64_t | syn_cbor_read_uint (SYN_CborReader * r) Read an unsigned integer (major type 0). |
| void | syn_cbor_reader_init (SYN_CborReader * r, const uint8_t * buf, size_t len) Initialize a CBOR reader. |
| void | syn_cbor_skip (SYN_CborReader * r) Skip the next complete item (including nested contents). |
Public Static Functions¶
| Type | Name |
|---|---|
| uint8_t | consume_byte (SYN_CborReader * r) Consume and return one byte from the CBOR stream. |
| uint64_t | decode_arg (SYN_CborReader * r, uint8_t info) Decode a CBOR argument from the bottom-5-bit info field. |
| uint8_t | peek_byte (const SYN_CborReader * r) Peek at the next byte without consuming it. |
Macros¶
| Type | Name |
|---|---|
| define | SKIP_MAX_DEPTH 8uMaximum nesting depth for syn_cbor_skip. |
Public Functions Documentation¶
function syn_cbor_peek_type¶
Return the type of the next item without consuming it.
Parameters:
rReader.
Returns:
Item type, or SYN_CBOR_ERROR on buffer underrun.
function syn_cbor_read_array_begin¶
Consume an array header; return the number of items.
Parameters:
rReader.
Returns:
Item count, or 0 on error.
function syn_cbor_read_bool¶
Read a boolean (major type 7, info 20 or 21).
Parameters:
rReader.
Returns:
Decoded value, or false on error.
function syn_cbor_read_bytes¶
Read a byte string into a caller-provided buffer.
Copies at most cap bytes. The CBOR item is fully consumed.
Parameters:
rReader.bufOutput buffer.capOutput buffer capacity.
Returns:
Actual byte count in the CBOR item (may exceed cap).
function syn_cbor_read_float¶
Read a float32 value (major type 7, info=26).
Parameters:
rReader.
Returns:
Decoded float, or 0.0f on error.
function syn_cbor_read_int¶
Read a signed integer (major type 0 or 1).
Parameters:
rReader.
Returns:
Decoded value, or 0 on error.
function syn_cbor_read_map_begin¶
Consume a map header; return the number of key-value pairs.
Parameters:
rReader.
Returns:
Pair count, or 0 on error.
function syn_cbor_read_null¶
Consume a null item (major type 7, info=22).
Parameters:
rReader.
function syn_cbor_read_text¶
Read a text string into a caller-provided buffer.
Copies at most cap-1 bytes and null-terminates. The CBOR item is fully consumed regardless of buffer capacity.
Parameters:
rReader.bufOutput buffer.capOutput buffer capacity (including space for null terminator).
Returns:
Actual UTF-8 byte count in the CBOR item (may exceed cap-1).
function syn_cbor_read_uint¶
Read an unsigned integer (major type 0).
Parameters:
rReader.
Returns:
Decoded value, or 0 on error.
function syn_cbor_reader_init¶
Initialize a CBOR reader.
Parameters:
rReader to initialize.bufInput buffer containing encoded CBOR.lenBuffer length in bytes.
function syn_cbor_skip¶
Skip the next complete item (including nested contents).
Handles nested arrays and maps up to 8 levels deep.
Parameters:
rReader.
Public Static Functions Documentation¶
function consume_byte¶
Consume and return one byte from the CBOR stream.
Parameters:
rCBOR reader.
Returns:
Consumed byte, or 0 on underrun.
function decode_arg¶
Decode a CBOR argument from the bottom-5-bit info field.
Reads the argument value associated with info. Consumes 0, 1, 2, 4, or 8 additional bytes. Sets r->ok = false for reserved info values.
Parameters:
rCBOR reader.infoBottom 5 bits of the header byte.
Returns:
Decoded argument value.
function peek_byte¶
Peek at the next byte without consuming it.
Parameters:
rCBOR reader.
Returns:
Next byte, or 0 if at end.
Macro Definition Documentation¶
define SKIP_MAX_DEPTH¶
Maximum nesting depth for syn_cbor_skip.
The documentation for this class was generated from the following file src/syntropic/util/syn_cbor_read.c