1 /*
2  * Copyright (c) 2022 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Generated using zcbor version 0.8.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 static bool decode_Pet(zcbor_state_t *state, struct Pet *result);
24 
25 
decode_Pet(zcbor_state_t * state,struct Pet * result)26 static bool decode_Pet(
27 		zcbor_state_t *state, struct Pet *result)
28 {
29 	zcbor_log("%s\r\n", __func__);
30 
31 	bool tmp_result = (((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)))
32 	&& ((zcbor_bstr_decode(state, (&(*result).birthday)))
33 	&& ((((((*result).birthday.len >= 8)
34 	&& ((*result).birthday.len <= 8)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))
35 	&& ((((zcbor_uint_decode(state, &(*result).species_choice, sizeof((*result).species_choice)))) && ((((((*result).species_choice == Pet_species_cat_c) && ((1)))
36 	|| (((*result).species_choice == Pet_species_dog_c) && ((1)))
37 	|| (((*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))));
38 
39 	if (!tmp_result) {
40 		zcbor_trace_file(state);
41 		zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
42 	} else {
43 		zcbor_log("%s success\r\n", __func__);
44 	}
45 
46 	return tmp_result;
47 }
48 
49 
50 
cbor_decode_Pet(const uint8_t * payload,size_t payload_len,struct Pet * result,size_t * payload_len_out)51 int cbor_decode_Pet(
52 		const uint8_t *payload, size_t payload_len,
53 		struct Pet *result,
54 		size_t *payload_len_out)
55 {
56 	zcbor_state_t states[4];
57 
58 	return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states,
59 		(zcbor_decoder_t *)decode_Pet, sizeof(states) / sizeof(zcbor_state_t), 1);
60 }
61