Golioth Firmware SDK
Loading...
Searching...
No Matches
zcbor_utils.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Golioth, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifdef __cplusplus
8extern "C"
9{
10#endif
11
12#include <zcbor_decode.h>
13#include <zcbor_encode.h>
14
15enum
16{
19};
20
22{
23 uint8_t type;
24 union
25 {
26 uint32_t u32;
27 struct zcbor_string tstr;
28 };
29};
30
32{
34 int (*decode)(zcbor_state_t *zsd, void *value);
35 void *value;
36};
37
44static inline bool zcbor_list_or_map_end(zcbor_state_t *state)
45{
46 if (state->decode_state.indefinite_length_array)
47 {
48 return *state->payload == 0xff;
49 }
50
51 return state->elem_count == 0;
52}
53
65int zcbor_map_int64_decode(zcbor_state_t *zsd, void *value);
66
79int zcbor_map_tstr_decode(zcbor_state_t *zsd, void *value);
80
96int zcbor_map_decode(zcbor_state_t *zsd, struct zcbor_map_entry *entries, size_t num_entries);
97
105#define ZCBOR_U32_MAP_ENTRY(_u32, _decode, _value) \
106 { \
107 .key = \
108 { \
109 .type = ZCBOR_MAP_KEY_TYPE_U32, \
110 .u32 = _u32, \
111 }, \
112 .decode = _decode, .value = _value, \
113 }
114
122#define ZCBOR_TSTR_LIT_MAP_ENTRY(_tstr_lit, _decode, _value) \
123 { \
124 .key = \
125 { \
126 .type = ZCBOR_MAP_KEY_TYPE_TSTR, \
127 .tstr = {(const uint8_t *) _tstr_lit, sizeof(_tstr_lit) - 1}, \
128 }, \
129 .decode = _decode, .value = _value, \
130 }
131
132#ifdef __cplusplus
133}
134#endif
Definition zcbor_utils.h:32
struct zcbor_map_key key
Definition zcbor_utils.h:33
int(* decode)(zcbor_state_t *zsd, void *value)
Definition zcbor_utils.h:34
void * value
Definition zcbor_utils.h:35
uint32_t u32
Definition zcbor_utils.h:26
struct zcbor_string tstr
Definition zcbor_utils.h:27
int zcbor_map_tstr_decode(zcbor_state_t *zsd, void *value)
Decode text string value from CBOR map.
@ ZCBOR_MAP_KEY_TYPE_U32
Definition zcbor_utils.h:17
@ ZCBOR_MAP_KEY_TYPE_TSTR
Definition zcbor_utils.h:18
int zcbor_map_int64_decode(zcbor_state_t *zsd, void *value)
Decode int64_t 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.
static bool zcbor_list_or_map_end(zcbor_state_t *state)
Check the end of CBOR list or map.
Definition zcbor_utils.h:44