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
8
extern
"C"
9
{
10
#endif
11
12
#include <zcbor_decode.h>
13
#include <zcbor_encode.h>
14
15
enum
16
{
17
ZCBOR_MAP_KEY_TYPE_U32
,
18
ZCBOR_MAP_KEY_TYPE_TSTR
,
19
};
20
21
struct
zcbor_map_key
22
{
23
uint8_t
type
;
24
union
25
{
26
uint32_t
u32
;
27
struct
zcbor_string
tstr
;
28
};
29
};
30
31
struct
zcbor_map_entry
32
{
33
struct
zcbor_map_key
key
;
34
int (*
decode
)(zcbor_state_t *zsd,
void
*
value
);
35
void
*
value
;
36
};
37
44
static
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
65
int
zcbor_map_int64_decode
(zcbor_state_t *zsd,
void
*value);
66
79
int
zcbor_map_tstr_decode
(zcbor_state_t *zsd,
void
*value);
80
96
int
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
zcbor_map_entry
Definition
zcbor_utils.h:32
zcbor_map_entry::key
struct zcbor_map_key key
Definition
zcbor_utils.h:33
zcbor_map_entry::decode
int(* decode)(zcbor_state_t *zsd, void *value)
Definition
zcbor_utils.h:34
zcbor_map_entry::value
void * value
Definition
zcbor_utils.h:35
zcbor_map_key
Definition
zcbor_utils.h:22
zcbor_map_key::type
uint8_t type
Definition
zcbor_utils.h:23
zcbor_map_key::u32
uint32_t u32
Definition
zcbor_utils.h:26
zcbor_map_key::tstr
struct zcbor_string tstr
Definition
zcbor_utils.h:27
zcbor_map_tstr_decode
int zcbor_map_tstr_decode(zcbor_state_t *zsd, void *value)
Decode text string value from CBOR map.
ZCBOR_MAP_KEY_TYPE_U32
@ ZCBOR_MAP_KEY_TYPE_U32
Definition
zcbor_utils.h:17
ZCBOR_MAP_KEY_TYPE_TSTR
@ ZCBOR_MAP_KEY_TYPE_TSTR
Definition
zcbor_utils.h:18
zcbor_map_int64_decode
int zcbor_map_int64_decode(zcbor_state_t *zsd, void *value)
Decode int64_t value from CBOR map.
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.
zcbor_list_or_map_end
static bool zcbor_list_or_map_end(zcbor_state_t *state)
Check the end of CBOR list or map.
Definition
zcbor_utils.h:44
include
golioth
zcbor_utils.h
Generated on Thu Nov 21 2024 03:32:16 for Golioth Firmware SDK by
1.10.0