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