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_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 #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 encode_Pet(zcbor_state_t *state, const struct Pet *input);
33
34
encode_Pet(zcbor_state_t * state,const struct Pet * input)35 static bool encode_Pet(
36 zcbor_state_t *state, const struct Pet *input)
37 {
38 zcbor_log("%s\r\n", __func__);
39
40 bool res = (((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)))
41 && (((((((*input).birthday.len == 8)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))
42 && (zcbor_bstr_encode(state, (&(*input).birthday))))
43 && ((((*input).species_choice == Pet_species_cat_c) ? ((zcbor_uint32_put(state, (1))))
44 : (((*input).species_choice == Pet_species_dog_c) ? ((zcbor_uint32_put(state, (2))))
45 : (((*input).species_choice == Pet_species_other_c) ? ((zcbor_uint32_put(state, (3))))
46 : false))))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 3))));
47
48 log_result(state, res, __func__);
49 return res;
50 }
51
52
53
cbor_encode_Pet(uint8_t * payload,size_t payload_len,const struct Pet * input,size_t * payload_len_out)54 int cbor_encode_Pet(
55 uint8_t *payload, size_t payload_len,
56 const struct Pet *input,
57 size_t *payload_len_out)
58 {
59 zcbor_state_t states[4];
60
61 return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states,
62 (zcbor_decoder_t *)encode_Pet, sizeof(states) / sizeof(zcbor_state_t), 1);
63 }
64