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_message_error.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_message_error_C_x(zcbor_state_t *state, const struct message_error_C_x_r *input);
20 static bool encode_repeated_message_error_SUITES_R(zcbor_state_t *state, const struct message_error_SUITES_R_r *input);
21 static bool encode_message_error(zcbor_state_t *state, const struct message_error *input);
22
23
encode_repeated_message_error_C_x(zcbor_state_t * state,const struct message_error_C_x_r * input)24 static bool encode_repeated_message_error_C_x(
25 zcbor_state_t *state, const struct message_error_C_x_r *input)
26 {
27 zcbor_log("%s\r\n", __func__);
28
29 bool tmp_result = (((((*input).message_error_C_x_choice == message_error_C_x_bstr_c) ? ((zcbor_bstr_encode(state, (&(*input).message_error_C_x_bstr))))
30 : (((*input).message_error_C_x_choice == message_error_C_x_int_c) ? ((zcbor_int32_encode(state, (&(*input).message_error_C_x_int))))
31 : false))));
32
33 if (!tmp_result) {
34 zcbor_trace_file(state);
35 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
36 } else {
37 zcbor_log("%s success\r\n", __func__);
38 }
39
40 return tmp_result;
41 }
42
encode_repeated_message_error_SUITES_R(zcbor_state_t * state,const struct message_error_SUITES_R_r * input)43 static bool encode_repeated_message_error_SUITES_R(
44 zcbor_state_t *state, const struct message_error_SUITES_R_r *input)
45 {
46 zcbor_log("%s\r\n", __func__);
47
48 bool tmp_result = (((((*input).message_error_SUITES_R_choice == SUITES_R_supported_l_c) ? ((zcbor_list_start_encode(state, 10) && ((zcbor_multi_encode_minmax(2, 10, &(*input).SUITES_R_supported_l_supported_count, (zcbor_encoder_t *)zcbor_int32_encode, state, (&(*input).SUITES_R_supported_l_supported), sizeof(int32_t))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 10)))
49 : (((*input).message_error_SUITES_R_choice == message_error_SUITES_R_int_c) ? ((zcbor_int32_encode(state, (&(*input).message_error_SUITES_R_int))))
50 : false))));
51
52 if (!tmp_result) {
53 zcbor_trace_file(state);
54 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
55 } else {
56 zcbor_log("%s success\r\n", __func__);
57 }
58
59 return tmp_result;
60 }
61
encode_message_error(zcbor_state_t * state,const struct message_error * input)62 static bool encode_message_error(
63 zcbor_state_t *state, const struct message_error *input)
64 {
65 zcbor_log("%s\r\n", __func__);
66
67 bool tmp_result = ((((!(*input).message_error_C_x_present || encode_repeated_message_error_C_x(state, (&(*input).message_error_C_x)))
68 && ((zcbor_tstr_encode(state, (&(*input).message_error_DIAG_MSG))))
69 && (!(*input).message_error_SUITES_R_present || encode_repeated_message_error_SUITES_R(state, (&(*input).message_error_SUITES_R))))));
70
71 if (!tmp_result) {
72 zcbor_trace_file(state);
73 zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
74 } else {
75 zcbor_log("%s success\r\n", __func__);
76 }
77
78 return tmp_result;
79 }
80
81
82
cbor_encode_message_error(uint8_t * payload,size_t payload_len,const struct message_error * input,size_t * payload_len_out)83 int cbor_encode_message_error(
84 uint8_t *payload, size_t payload_len,
85 const struct message_error *input,
86 size_t *payload_len_out)
87 {
88 zcbor_state_t states[4];
89
90 return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states,
91 (zcbor_decoder_t *)encode_message_error, sizeof(states) / sizeof(zcbor_state_t), 3);
92 }
93