1 /*
2  * Copyright (c) 2022 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Generated using zcbor version 0.7.0
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 
18 #if DEFAULT_MAX_QTY != 3
19 #error "The type file was generated with a different default_max_qty than this file"
20 #endif
21 
22 static bool decode_Pet(zcbor_state_t *state, struct Pet *result);
23 
24 
decode_Pet(zcbor_state_t * state,struct Pet * result)25 static bool decode_Pet(
26 		zcbor_state_t *state, struct Pet *result)
27 {
28 	zcbor_print("%s\r\n", __func__);
29 
30 	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)))
31 	&& ((zcbor_bstr_decode(state, (&(*result).birthday)))
32 	&& ((((((*result).birthday.len >= 8)
33 	&& ((*result).birthday.len <= 8)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))
34 	&& ((((zcbor_int_decode(state, &(*result).species_choice, sizeof((*result).species_choice)))) && ((((((*result).species_choice == _Pet_species_cat) && ((1)))
35 	|| (((*result).species_choice == _Pet_species_dog) && ((1)))
36 	|| (((*result).species_choice == _Pet_species_other) && ((1)))) || (zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false)))))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state))));
37 
38 	if (!tmp_result)
39 		zcbor_trace();
40 
41 	return tmp_result;
42 }
43 
44 
45 
cbor_decode_Pet(const uint8_t * payload,size_t payload_len,struct Pet * result,size_t * payload_len_out)46 int cbor_decode_Pet(
47 		const uint8_t *payload, size_t payload_len,
48 		struct Pet *result,
49 		size_t *payload_len_out)
50 {
51 	zcbor_state_t states[4];
52 
53 	zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1);
54 
55 	bool ret = decode_Pet(states, result);
56 
57 	if (ret && (payload_len_out != NULL)) {
58 		*payload_len_out = MIN(payload_len,
59 				(size_t)states[0].payload - (size_t)payload);
60 	}
61 
62 	if (!ret) {
63 		int err = zcbor_pop_error(states);
64 
65 		zcbor_print("Return error: %d\r\n", err);
66 		return (err == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : err;
67 	}
68 	return ZCBOR_SUCCESS;
69 }
70