1 /*
2 * Generated using zcbor version 0.8.0
3 * https://github.com/NordicSemiconductor/zcbor
4 * Generated with a --default-max-qty of 3
5 */
6
7 #include <stdint.h>
8 #include <stdbool.h>
9 #include <stddef.h>
10 #include <string.h>
11 #include "zcbor_encode.h"
12 #include "cbor/edhoc_encode_data_2.h"
13 #include "zcbor_print.h"
14
15 #if DEFAULT_MAX_QTY != 3
16 #error "The type file was generated with a different default_max_qty than this file"
17 #endif
18
19 static bool encode_repeated_data_2_C_I(zcbor_state_t *state, const struct data_2_C_I_r *input);
20 static bool encode_data_2(zcbor_state_t *state, const struct data_2 *input);
21
22
encode_repeated_data_2_C_I(zcbor_state_t * state,const struct data_2_C_I_r * input)23 static bool encode_repeated_data_2_C_I(
24 zcbor_state_t *state, const struct data_2_C_I_r *input)
25 {
26 zcbor_log("%s\r\n", __func__);
27
28 bool tmp_result = (((((*input).data_2_C_I_choice == data_2_C_I_int_c) ? ((zcbor_int32_encode(state, (&(*input).data_2_C_I_int))))
29 : (((*input).data_2_C_I_choice == data_2_C_I_bstr_c) ? ((zcbor_bstr_encode(state, (&(*input).data_2_C_I_bstr))))
30 : false))));
31
32 if (!tmp_result) {
33 zcbor_trace_file(state);
34 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
35 } else {
36 zcbor_log("%s success\r\n", __func__);
37 }
38
39 return tmp_result;
40 }
41
encode_data_2(zcbor_state_t * state,const struct data_2 * input)42 static bool encode_data_2(
43 zcbor_state_t *state, const struct data_2 *input)
44 {
45 zcbor_log("%s\r\n", __func__);
46
47 bool tmp_result = ((((!(*input).data_2_C_I_present || encode_repeated_data_2_C_I(state, (&(*input).data_2_C_I)))
48 && ((zcbor_bstr_encode(state, (&(*input).data_2_G_Y))))
49 && ((((*input).data_2_C_R_choice == data_2_C_R_int_c) ? ((zcbor_int32_encode(state, (&(*input).data_2_C_R_int))))
50 : (((*input).data_2_C_R_choice == data_2_C_R_bstr_c) ? ((zcbor_bstr_encode(state, (&(*input).data_2_C_R_bstr))))
51 : false))))));
52
53 if (!tmp_result) {
54 zcbor_trace_file(state);
55 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
56 } else {
57 zcbor_log("%s success\r\n", __func__);
58 }
59
60 return tmp_result;
61 }
62
63
64
cbor_encode_data_2(uint8_t * payload,size_t payload_len,const struct data_2 * input,size_t * payload_len_out)65 int cbor_encode_data_2(
66 uint8_t *payload, size_t payload_len,
67 const struct data_2 *input,
68 size_t *payload_len_out)
69 {
70 zcbor_state_t states[3];
71
72 return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states,
73 (zcbor_decoder_t *)encode_data_2, sizeof(states) / sizeof(zcbor_state_t), 3);
74 }
75