Golioth Firmware SDK
Loading...
Searching...
No Matches
zcbor_utils.h File Reference
#include <zcbor_decode.h>
#include <zcbor_encode.h>

Go to the source code of this file.

Data Structures

struct  zcbor_map_key
 
struct  zcbor_map_entry
 

Macros

#define ZCBOR_STATE_D_COMPAT(name, num_backups, payload, payload_size, elem_count, n_flags)    ZCBOR_STATE_D(name, num_backups, payload, payload_size, elem_count, n_flags)
 
#define ZCBOR_U32_MAP_ENTRY(_u32, _decode, _value)
 Define CBOR map entry to be decoded, referenced by uint32_t key.
 
#define ZCBOR_TSTR_LIT_MAP_ENTRY(_tstr_lit, _decode, _value)
 Define CBOR map entry to be decoded, referenced by literal string key.
 

Enumerations

enum  { ZCBOR_MAP_KEY_TYPE_U32 , ZCBOR_MAP_KEY_TYPE_TSTR }
 

Functions

static bool zcbor_is_indefinite_length_array (zcbor_state_t *state)
 
static bool zcbor_tstr_put_term_compat (zcbor_state_t *state, char const *str, size_t maxlen)
 
static bool zcbor_list_or_map_end (zcbor_state_t *state)
 Check the end of CBOR list or map.
 
int zcbor_map_int64_decode (zcbor_state_t *zsd, void *value)
 Decode int64_t value from CBOR map.
 
int zcbor_map_tstr_decode (zcbor_state_t *zsd, void *value)
 Decode text string value from CBOR map.
 
int zcbor_map_decode (zcbor_state_t *zsd, struct zcbor_map_entry *entries, size_t num_entries)
 Decode CBOR map with specified entries.
 

Macro Definition Documentation

◆ ZCBOR_STATE_D_COMPAT

#define ZCBOR_STATE_D_COMPAT ( name,
num_backups,
payload,
payload_size,
elem_count,
n_flags )    ZCBOR_STATE_D(name, num_backups, payload, payload_size, elem_count, n_flags)

Definition at line 31 of file zcbor_utils.h.

◆ ZCBOR_TSTR_LIT_MAP_ENTRY

#define ZCBOR_TSTR_LIT_MAP_ENTRY ( _tstr_lit,
_decode,
_value )
Value:
{ \
.key = \
{ \
.tstr = {(const uint8_t *) _tstr_lit, sizeof(_tstr_lit) - 1}, \
}, \
.decode = _decode, .value = _value, \
}
@ ZCBOR_MAP_KEY_TYPE_TSTR
Definition zcbor_utils.h:49

Define CBOR map entry to be decoded, referenced by literal string key.

Parameters
_tstr_litMap key (literal string, e.g. "my_key")
_decodeMap value decode callback
_valueValue passed to decode callback

Definition at line 153 of file zcbor_utils.h.

◆ ZCBOR_U32_MAP_ENTRY

#define ZCBOR_U32_MAP_ENTRY ( _u32,
_decode,
_value )
Value:
{ \
.key = \
{ \
.u32 = _u32, \
}, \
.decode = _decode, .value = _value, \
}
@ ZCBOR_MAP_KEY_TYPE_U32
Definition zcbor_utils.h:48

Define CBOR map entry to be decoded, referenced by uint32_t key.

Parameters
_u32Map key
_decodeMap value decode callback
_valueValue passed to decode callback

Definition at line 136 of file zcbor_utils.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
ZCBOR_MAP_KEY_TYPE_U32 
ZCBOR_MAP_KEY_TYPE_TSTR 

Definition at line 46 of file zcbor_utils.h.

Function Documentation

◆ zcbor_is_indefinite_length_array()

static bool zcbor_is_indefinite_length_array ( zcbor_state_t * state)
inlinestatic

Definition at line 34 of file zcbor_utils.h.

◆ zcbor_list_or_map_end()

static bool zcbor_list_or_map_end ( zcbor_state_t * state)
inlinestatic

Check the end of CBOR list or map.

Return values
trueReached end of list or map
falseThere are more items (from list of map) to be processed

Definition at line 75 of file zcbor_utils.h.

◆ zcbor_map_decode()

int zcbor_map_decode ( zcbor_state_t * zsd,
struct zcbor_map_entry * entries,
size_t num_entries )

Decode CBOR map with specified entries.

Decode CBOR map with entries specified by entries. All specified entries need to exist in processed CBOR map.

Parameters
[in,out]zsdThe current state of the decoding
[in]entriesArray with entries to be decoded
[in]num_entriesNumber of entries (size of entries array)
Return values
0On success
-EBADMSGFailed to parse all map entries
-ENOENTMap was empty
<0Other error returned from @ entries decode callback

◆ zcbor_map_int64_decode()

int zcbor_map_int64_decode ( zcbor_state_t * zsd,
void * value )

Decode int64_t value from CBOR map.

Callback for decoding int64_t value from CBOR map using zcbor_map_decode().

Parameters
[in,out]zsdThe current state of the decoding
[out]valuePointer to int64_t value where result of decoding is saved.
Return values
0On success
<0POSIX error code on error

◆ zcbor_map_tstr_decode()

int zcbor_map_tstr_decode ( zcbor_state_t * zsd,
void * value )

Decode text string value from CBOR map.

Callback for decoding tstr (struct zcbor_string) value from CBOR map using zcbor_map_decode().

Parameters
[in,out]zsdThe current state of the decoding
[out]valuePointer to struct 'struct zcbor_string' value where result of decoding is saved.
Return values
0On success
<0POSIX error code on error

◆ zcbor_tstr_put_term_compat()

static bool zcbor_tstr_put_term_compat ( zcbor_state_t * state,
char const * str,
size_t maxlen )
inlinestatic

Definition at line 39 of file zcbor_utils.h.