1 /*
2 * Copyright (c) 2024 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Generated using zcbor version 0.9.0
7 * https://github.com/zephyrproject-rtos/zcbor
8 * Generated with a --default-max-qty of 99
9 */
10
11 #include <stdint.h>
12 #include <stdbool.h>
13 #include <stddef.h>
14 #include <string.h>
15 #include "zcbor_decode.h"
16 #include "lwm2m_senml_cbor_decode.h"
17 #include "zcbor_print.h"
18
19 #define log_result(state, result, func) \
20 do { \
21 if (!result) { \
22 zcbor_trace_file(state); \
23 zcbor_log("%s error: %s\r\n", func, \
24 zcbor_error_str(zcbor_peek_error(state))); \
25 } else { \
26 zcbor_log("%s success\r\n", func); \
27 } \
28 } while (0)
29
30 static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *result);
31 static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *result);
32 static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *result);
33 static bool decode_repeated_record_t(zcbor_state_t *state, struct record_t *result);
34 static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_r *result);
35 static bool decode_value(zcbor_state_t *state, struct value_r *result);
36 static bool decode_key_value_pair(zcbor_state_t *state, struct key_value_pair *result);
37 static bool decode_repeated_record_key_value_pair_m(zcbor_state_t *state,
38 struct record_key_value_pair_m *result);
39 static bool decode_record(zcbor_state_t *state, struct record *result);
40 static bool decode_lwm2m_senml(zcbor_state_t *state, struct lwm2m_senml *result);
41
decode_repeated_record_bn(zcbor_state_t * state,struct record_bn * result)42 static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *result)
43 {
44 zcbor_log("%s\r\n", __func__);
45
46 bool res = ((((zcbor_int32_expect(state, (-2)))) &&
47 (zcbor_tstr_decode(state, (&(*result).record_bn)))));
48
49 log_result(state, res, __func__);
50 return res;
51 }
52
decode_repeated_record_bt(zcbor_state_t * state,struct record_bt * result)53 static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *result)
54 {
55 zcbor_log("%s\r\n", __func__);
56
57 bool res = ((((zcbor_int32_expect(state, (-3)))) &&
58 (zcbor_int64_decode(state, (&(*result).record_bt)))));
59
60 log_result(state, res, __func__);
61 return res;
62 }
63
decode_repeated_record_n(zcbor_state_t * state,struct record_n * result)64 static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *result)
65 {
66 zcbor_log("%s\r\n", __func__);
67
68 bool res = ((((zcbor_uint32_expect(state, (0)))) &&
69 (zcbor_tstr_decode(state, (&(*result).record_n)))));
70
71 log_result(state, res, __func__);
72 return res;
73 }
74
decode_repeated_record_t(zcbor_state_t * state,struct record_t * result)75 static bool decode_repeated_record_t(zcbor_state_t *state, struct record_t *result)
76 {
77 zcbor_log("%s\r\n", __func__);
78
79 bool res = ((((zcbor_uint32_expect(state, (6)))) &&
80 (zcbor_int64_decode(state, (&(*result).record_t)))));
81
82 log_result(state, res, __func__);
83 return res;
84 }
85
decode_repeated_record_union(zcbor_state_t * state,struct record_union_r * result)86 static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_r *result)
87 {
88 zcbor_log("%s\r\n", __func__);
89 struct zcbor_string tmp_str;
90 bool int_res;
91
92 bool res = (((zcbor_union_start_code(state) &&
93 (int_res = (((((zcbor_uint32_expect_union(state, (2)))) &&
94 (zcbor_int64_decode(state, (&(*result).union_vi)))) &&
95 (((*result).record_union_choice = union_vi_c), true)) ||
96 ((((zcbor_uint32_expect_union(state, (2)))) &&
97 (zcbor_float_decode(state, (&(*result).union_vf)))) &&
98 (((*result).record_union_choice = union_vf_c), true)) ||
99 ((((zcbor_uint32_expect_union(state, (3)))) &&
100 (zcbor_tstr_decode(state, (&(*result).union_vs)))) &&
101 (((*result).record_union_choice = union_vs_c), true)) ||
102 ((((zcbor_uint32_expect_union(state, (4)))) &&
103 (zcbor_bool_decode(state, (&(*result).union_vb)))) &&
104 (((*result).record_union_choice = union_vb_c), true)) ||
105 ((((zcbor_uint32_expect_union(state, (8)))) &&
106 (zcbor_bstr_decode(state, (&(*result).union_vd)))) &&
107 (((*result).record_union_choice = union_vd_c), true)) ||
108 (zcbor_union_elem_code(state) &&
109 ((((zcbor_tstr_expect(state, ((tmp_str.value = (uint8_t *)"vlo",
110 tmp_str.len = sizeof("vlo") - 1,
111 &tmp_str))))) &&
112 (zcbor_tstr_decode(state, (&(*result).union_vlo)))) &&
113 (((*result).record_union_choice = union_vlo_c), true)))),
114 zcbor_union_end_code(state), int_res))));
115
116 log_result(state, res, __func__);
117 return res;
118 }
119
decode_value(zcbor_state_t * state,struct value_r * result)120 static bool decode_value(zcbor_state_t *state, struct value_r *result)
121 {
122 zcbor_log("%s\r\n", __func__);
123 bool int_res;
124
125 bool res = (((zcbor_union_start_code(state) &&
126 (int_res = ((((zcbor_tstr_decode(state, (&(*result).value_tstr)))) &&
127 (((*result).value_choice = value_tstr_c), true)) ||
128 (((zcbor_bstr_decode(state, (&(*result).value_bstr)))) &&
129 (((*result).value_choice = value_bstr_c), true)) ||
130 (((zcbor_int64_decode(state, (&(*result).value_int)))) &&
131 (((*result).value_choice = value_int_c), true)) ||
132 (zcbor_union_elem_code(state) &&
133 (((zcbor_float_decode(state, (&(*result).value_float)))) &&
134 (((*result).value_choice = value_float_c), true))) ||
135 (((zcbor_bool_decode(state, (&(*result).value_bool)))) &&
136 (((*result).value_choice = value_bool_c), true))),
137 zcbor_union_end_code(state), int_res))));
138
139 log_result(state, res, __func__);
140 return res;
141 }
142
decode_key_value_pair(zcbor_state_t * state,struct key_value_pair * result)143 static bool decode_key_value_pair(zcbor_state_t *state, struct key_value_pair *result)
144 {
145 zcbor_log("%s\r\n", __func__);
146
147 bool res = ((((zcbor_int32_decode(state, (&(*result).key_value_pair_key)))) &&
148 (decode_value(state, (&(*result).key_value_pair)))));
149
150 log_result(state, res, __func__);
151 return res;
152 }
153
decode_repeated_record_key_value_pair_m(zcbor_state_t * state,struct record_key_value_pair_m * result)154 static bool decode_repeated_record_key_value_pair_m(zcbor_state_t *state,
155 struct record_key_value_pair_m *result)
156 {
157 zcbor_log("%s\r\n", __func__);
158
159 bool res = (((decode_key_value_pair(state, (&(*result).record_key_value_pair_m)))));
160
161 log_result(state, res, __func__);
162 return res;
163 }
164
decode_record(zcbor_state_t * state,struct record * result)165 static bool decode_record(zcbor_state_t *state, struct record *result)
166 {
167 zcbor_log("%s\r\n", __func__);
168
169 bool res =
170 (((zcbor_map_start_decode(state) &&
171 ((zcbor_present_decode(&((*result).record_bn_present),
172 (zcbor_decoder_t *)decode_repeated_record_bn, state,
173 (&(*result).record_bn)) &&
174 zcbor_present_decode(&((*result).record_bt_present),
175 (zcbor_decoder_t *)decode_repeated_record_bt, state,
176 (&(*result).record_bt)) &&
177 zcbor_present_decode(&((*result).record_n_present),
178 (zcbor_decoder_t *)decode_repeated_record_n, state,
179 (&(*result).record_n)) &&
180 zcbor_present_decode(&((*result).record_t_present),
181 (zcbor_decoder_t *)decode_repeated_record_t, state,
182 (&(*result).record_t)) &&
183 zcbor_present_decode(&((*result).record_union_present),
184 (zcbor_decoder_t *)decode_repeated_record_union, state,
185 (&(*result).record_union)) &&
186 zcbor_multi_decode(0, ZCBOR_ARRAY_SIZE(result->record_key_value_pair_m),
187 &(*result).record_key_value_pair_m_count,
188 (zcbor_decoder_t *)decode_repeated_record_key_value_pair_m,
189 state, (*&(*result).record_key_value_pair_m),
190 sizeof(struct record_key_value_pair_m))) ||
191 (zcbor_list_map_end_force_decode(state), false)) &&
192 zcbor_map_end_decode(state))));
193
194 if (false) {
195 /* For testing that the types of the arguments are correct.
196 * A compiler error here means a bug in zcbor.
197 */
198 decode_repeated_record_key_value_pair_m(state,
199 (*&(*result).record_key_value_pair_m));
200 decode_repeated_record_bn(state, (&(*result).record_bn));
201 decode_repeated_record_bt(state, (&(*result).record_bt));
202 decode_repeated_record_n(state, (&(*result).record_n));
203 decode_repeated_record_t(state, (&(*result).record_t));
204 decode_repeated_record_union(state, (&(*result).record_union));
205 }
206
207 log_result(state, res, __func__);
208 return res;
209 }
210
decode_lwm2m_senml(zcbor_state_t * state,struct lwm2m_senml * result)211 static bool decode_lwm2m_senml(zcbor_state_t *state, struct lwm2m_senml *result)
212 {
213 zcbor_log("%s\r\n", __func__);
214
215 bool res =
216 (((zcbor_list_start_decode(state) &&
217 ((zcbor_multi_decode(
218 1, ZCBOR_ARRAY_SIZE(result->lwm2m_senml_record_m),
219 &(*result).lwm2m_senml_record_m_count, (zcbor_decoder_t *)decode_record,
220 state, (*&(*result).lwm2m_senml_record_m), sizeof(struct record))) ||
221 (zcbor_list_map_end_force_decode(state), false)) &&
222 zcbor_list_end_decode(state))));
223
224 if (false) {
225 /* For testing that the types of the arguments are correct.
226 * A compiler error here means a bug in zcbor.
227 */
228 decode_record(state, (*&(*result).lwm2m_senml_record_m));
229 }
230
231 log_result(state, res, __func__);
232 return res;
233 }
234
cbor_decode_lwm2m_senml(const uint8_t * payload,size_t payload_len,struct lwm2m_senml * result,size_t * payload_len_out)235 int cbor_decode_lwm2m_senml(const uint8_t *payload, size_t payload_len, struct lwm2m_senml *result,
236 size_t *payload_len_out)
237 {
238 zcbor_state_t states[5];
239
240 return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states,
241 (zcbor_decoder_t *)decode_lwm2m_senml,
242 sizeof(states) / sizeof(zcbor_state_t), 1);
243 }
244