1 /*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Generated using zcbor version 0.8.1
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 static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *result);
20 static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *result);
21 static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *result);
22 static bool decode_repeated_record_t(zcbor_state_t *state, struct record_t *result);
23 static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_r *result);
24 static bool decode_value(zcbor_state_t *state, struct value_r *result);
25 static bool decode_key_value_pair(zcbor_state_t *state, struct key_value_pair *result);
26 static bool decode_repeated_record_key_value_pair_m(zcbor_state_t *state,
27 struct record_key_value_pair_m *result);
28 static bool decode_record(zcbor_state_t *state, struct record *result);
29 static bool decode_lwm2m_senml(zcbor_state_t *state, struct lwm2m_senml *result);
30
decode_repeated_record_bn(zcbor_state_t * state,struct record_bn * result)31 static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *result)
32 {
33 zcbor_log("%s\r\n", __func__);
34
35 bool tmp_result = ((((zcbor_int32_expect(state, (-2)))) &&
36 (zcbor_tstr_decode(state, (&(*result).record_bn)))));
37
38 if (!tmp_result) {
39 zcbor_trace_file(state);
40 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
41 } else {
42 zcbor_log("%s success\r\n", __func__);
43 }
44
45 return tmp_result;
46 }
47
decode_repeated_record_bt(zcbor_state_t * state,struct record_bt * result)48 static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *result)
49 {
50 zcbor_log("%s\r\n", __func__);
51
52 bool tmp_result =
53 ((((zcbor_int32_expect(state, (-3)))) &&
54 (zcbor_int64_decode(state, (&(*result).record_bt))) &&
55 ((((*result).record_bt >= INT64_MIN) && ((*result).record_bt <= INT64_MAX)) ||
56 (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))));
57
58 if (!tmp_result) {
59 zcbor_trace_file(state);
60 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
61 } else {
62 zcbor_log("%s success\r\n", __func__);
63 }
64
65 return tmp_result;
66 }
67
decode_repeated_record_n(zcbor_state_t * state,struct record_n * result)68 static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *result)
69 {
70 zcbor_log("%s\r\n", __func__);
71
72 bool tmp_result = ((((zcbor_uint32_expect(state, (0)))) &&
73 (zcbor_tstr_decode(state, (&(*result).record_n)))));
74
75 if (!tmp_result) {
76 zcbor_trace_file(state);
77 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
78 } else {
79 zcbor_log("%s success\r\n", __func__);
80 }
81
82 return tmp_result;
83 }
84
decode_repeated_record_t(zcbor_state_t * state,struct record_t * result)85 static bool decode_repeated_record_t(zcbor_state_t *state, struct record_t *result)
86 {
87 zcbor_log("%s\r\n", __func__);
88
89 bool tmp_result =
90 ((((zcbor_uint32_expect(state, (6)))) &&
91 (zcbor_int64_decode(state, (&(*result).record_t))) &&
92 ((((*result).record_t >= INT64_MIN) && ((*result).record_t <= INT64_MAX)) ||
93 (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))));
94
95 if (!tmp_result) {
96 zcbor_trace_file(state);
97 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
98 } else {
99 zcbor_log("%s success\r\n", __func__);
100 }
101
102 return tmp_result;
103 }
104
decode_repeated_record_union(zcbor_state_t * state,struct record_union_r * result)105 static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_r *result)
106 {
107 zcbor_log("%s\r\n", __func__);
108 struct zcbor_string tmp_str;
109 bool int_res;
110
111 bool tmp_result =
112 (((zcbor_union_start_code(state) &&
113 (int_res = (((((zcbor_uint32_expect_union(state, (2)))) &&
114 (zcbor_int64_decode(state, (&(*result).union_vi))) &&
115 ((((*result).union_vi >= INT64_MIN) &&
116 ((*result).union_vi <= INT64_MAX)) ||
117 (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) &&
118 (((*result).record_union_choice = union_vi_c), true)) ||
119 ((((zcbor_uint32_expect_union(state, (2)))) &&
120 (zcbor_float_decode(state, (&(*result).union_vf)))) &&
121 (((*result).record_union_choice = union_vf_c), true)) ||
122 ((((zcbor_uint32_expect_union(state, (3)))) &&
123 (zcbor_tstr_decode(state, (&(*result).union_vs)))) &&
124 (((*result).record_union_choice = union_vs_c), true)) ||
125 ((((zcbor_uint32_expect_union(state, (4)))) &&
126 (zcbor_bool_decode(state, (&(*result).union_vb)))) &&
127 (((*result).record_union_choice = union_vb_c), true)) ||
128 ((((zcbor_uint32_expect_union(state, (8)))) &&
129 (zcbor_bstr_decode(state, (&(*result).union_vd)))) &&
130 (((*result).record_union_choice = union_vd_c), true)) ||
131 (zcbor_union_elem_code(state) &&
132 ((((zcbor_tstr_expect(
133 state, ((tmp_str.value = (uint8_t *)"vlo",
134 tmp_str.len = sizeof("vlo") - 1, &tmp_str))))) &&
135 (zcbor_tstr_decode(state, (&(*result).union_vlo)))) &&
136 (((*result).record_union_choice = union_vlo_c), true)))),
137 zcbor_union_end_code(state), int_res))));
138
139 if (!tmp_result) {
140 zcbor_trace_file(state);
141 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
142 } else {
143 zcbor_log("%s success\r\n", __func__);
144 }
145
146 return tmp_result;
147 }
148
decode_value(zcbor_state_t * state,struct value_r * result)149 static bool decode_value(zcbor_state_t *state, struct value_r *result)
150 {
151 zcbor_log("%s\r\n", __func__);
152 bool int_res;
153
154 bool tmp_result = (((zcbor_union_start_code(state) &&
155 (int_res = ((((zcbor_tstr_decode(state, (&(*result).value_tstr)))) &&
156 (((*result).value_choice = value_tstr_c), true)) ||
157 (((zcbor_bstr_decode(state, (&(*result).value_bstr)))) &&
158 (((*result).value_choice = value_bstr_c), true)) ||
159 (((zcbor_int64_decode(state, (&(*result).value_int))) &&
160 ((((*result).value_int >= INT64_MIN) &&
161 ((*result).value_int <= INT64_MAX)) ||
162 (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) &&
163 (((*result).value_choice = value_int_c), true)) ||
164 (((zcbor_float_decode(state, (&(*result).value_float)))) &&
165 (((*result).value_choice = value_float_c), true)) ||
166 (((zcbor_bool_decode(state, (&(*result).value_bool)))) &&
167 (((*result).value_choice = value_bool_c), true))),
168 zcbor_union_end_code(state), int_res))));
169
170 if (!tmp_result) {
171 zcbor_trace_file(state);
172 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
173 } else {
174 zcbor_log("%s success\r\n", __func__);
175 }
176
177 return tmp_result;
178 }
179
decode_key_value_pair(zcbor_state_t * state,struct key_value_pair * result)180 static bool decode_key_value_pair(zcbor_state_t *state, struct key_value_pair *result)
181 {
182 zcbor_log("%s\r\n", __func__);
183
184 bool tmp_result = ((((zcbor_int32_decode(state, (&(*result).key_value_pair_key)))) &&
185 (decode_value(state, (&(*result).key_value_pair)))));
186
187 if (!tmp_result) {
188 zcbor_trace_file(state);
189 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
190 } else {
191 zcbor_log("%s success\r\n", __func__);
192 }
193
194 return tmp_result;
195 }
196
decode_repeated_record_key_value_pair_m(zcbor_state_t * state,struct record_key_value_pair_m * result)197 static bool decode_repeated_record_key_value_pair_m(zcbor_state_t *state,
198 struct record_key_value_pair_m *result)
199 {
200 zcbor_log("%s\r\n", __func__);
201
202 bool tmp_result = (((decode_key_value_pair(state, (&(*result).record_key_value_pair_m)))));
203
204 if (!tmp_result) {
205 zcbor_trace_file(state);
206 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
207 } else {
208 zcbor_log("%s success\r\n", __func__);
209 }
210
211 return tmp_result;
212 }
213
decode_record(zcbor_state_t * state,struct record * result)214 static bool decode_record(zcbor_state_t *state, struct record *result)
215 {
216 zcbor_log("%s\r\n", __func__);
217
218 bool tmp_result =
219 (((zcbor_map_start_decode(state) &&
220 ((zcbor_present_decode(&((*result).record_bn_present),
221 (zcbor_decoder_t *)decode_repeated_record_bn, state,
222 (&(*result).record_bn)) &&
223 zcbor_present_decode(&((*result).record_bt_present),
224 (zcbor_decoder_t *)decode_repeated_record_bt, state,
225 (&(*result).record_bt)) &&
226 zcbor_present_decode(&((*result).record_n_present),
227 (zcbor_decoder_t *)decode_repeated_record_n, state,
228 (&(*result).record_n)) &&
229 zcbor_present_decode(&((*result).record_t_present),
230 (zcbor_decoder_t *)decode_repeated_record_t, state,
231 (&(*result).record_t)) &&
232 zcbor_present_decode(&((*result).record_union_present),
233 (zcbor_decoder_t *)decode_repeated_record_union, state,
234 (&(*result).record_union)) &&
235 zcbor_multi_decode(0, ZCBOR_ARRAY_SIZE(result->record_key_value_pair_m),
236 &(*result).record_key_value_pair_m_count,
237 (zcbor_decoder_t *)decode_repeated_record_key_value_pair_m,
238 state, (&(*result).record_key_value_pair_m),
239 sizeof(struct record_key_value_pair_m))) ||
240 (zcbor_list_map_end_force_decode(state), false)) &&
241 zcbor_map_end_decode(state))));
242
243 if (!tmp_result) {
244 zcbor_trace_file(state);
245 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
246 } else {
247 zcbor_log("%s success\r\n", __func__);
248 }
249
250 return tmp_result;
251 }
252
decode_lwm2m_senml(zcbor_state_t * state,struct lwm2m_senml * result)253 static bool decode_lwm2m_senml(zcbor_state_t *state, struct lwm2m_senml *result)
254 {
255 zcbor_log("%s\r\n", __func__);
256
257 bool tmp_result =
258 (((zcbor_list_start_decode(state) &&
259 ((zcbor_multi_decode(
260 1, ZCBOR_ARRAY_SIZE(result->lwm2m_senml_record_m),
261 &(*result).lwm2m_senml_record_m_count, (zcbor_decoder_t *)decode_record,
262 state, (&(*result).lwm2m_senml_record_m), sizeof(struct record))) ||
263 (zcbor_list_map_end_force_decode(state), false)) &&
264 zcbor_list_end_decode(state))));
265
266 if (!tmp_result) {
267 zcbor_trace_file(state);
268 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
269 } else {
270 zcbor_log("%s success\r\n", __func__);
271 }
272
273 return tmp_result;
274 }
275
cbor_decode_lwm2m_senml(const uint8_t * payload,size_t payload_len,struct lwm2m_senml * result,size_t * payload_len_out)276 int cbor_decode_lwm2m_senml(const uint8_t *payload, size_t payload_len, struct lwm2m_senml *result,
277 size_t *payload_len_out)
278 {
279 zcbor_state_t states[5];
280
281 return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states,
282 (zcbor_decoder_t *)decode_lwm2m_senml,
283 sizeof(states) / sizeof(zcbor_state_t), 1);
284 }
285