1 /*
2  * Copyright (c) 2022 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Generated using zcbor version 0.9.1
7  * https://github.com/NordicSemiconductor/zcbor
8  * Generated with a --default-max-qty of 3
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 "pet_decode.h"
17 #include "zcbor_print.h"
18 
19 #if DEFAULT_MAX_QTY != 3
20 #error "The type file was generated with a different default_max_qty than this file"
21 #endif
22 
23 #define log_result(state, result, func) do { \
24 	if (!result) { \
25 		zcbor_trace_file(state); \
26 		zcbor_log("%s error: %s\r\n", func, zcbor_error_str(zcbor_peek_error(state))); \
27 	} else { \
28 		zcbor_log("%s success\r\n", func); \
29 	} \
30 } while(0)
31 
32 static bool decode_Pet(zcbor_state_t *state, struct Pet *result);
33 
34 
decode_Pet(zcbor_state_t * state,struct Pet * result)35 static bool decode_Pet(
36 		zcbor_state_t *state, struct Pet *result)
37 {
38 	zcbor_log("%s\r\n", __func__);
39 
40 	bool res = (((zcbor_list_start_decode(state) && ((((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, 3, &(*result).names_count, (zcbor_decoder_t *)zcbor_tstr_decode, state, (*&(*result).names), sizeof(struct zcbor_string))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))
41 	&& ((zcbor_bstr_decode(state, (&(*result).birthday)))
42 	&& ((((((*result).birthday.len == 8)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))
43 	&& ((((zcbor_uint_decode(state, &(*result).species_choice, sizeof((*result).species_choice)))) && ((((((*result).species_choice == Pet_species_cat_c) && ((1)))
44 	|| (((*result).species_choice == Pet_species_dog_c) && ((1)))
45 	|| (((*result).species_choice == Pet_species_other_c) && ((1)))) || (zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false)))))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state))));
46 
47 	if (false) {
48 		/* For testing that the types of the arguments are correct.
49 		 * A compiler error here means a bug in zcbor.
50 		 */
51 		zcbor_tstr_decode(state, (*&(*result).names));
52 	}
53 
54 	log_result(state, res, __func__);
55 	return res;
56 }
57 
58 
59 
cbor_decode_Pet(const uint8_t * payload,size_t payload_len,struct Pet * result,size_t * payload_len_out)60 int cbor_decode_Pet(
61 		const uint8_t *payload, size_t payload_len,
62 		struct Pet *result,
63 		size_t *payload_len_out)
64 {
65 	zcbor_state_t states[4];
66 
67 	return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states,
68 		(zcbor_decoder_t *)decode_Pet, sizeof(states) / sizeof(zcbor_state_t), 1);
69 }
70