1 /*
2 * Generated using zcbor version 0.3.99
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
14 #if DEFAULT_MAX_QTY != 3
15 #error "The type file was generated with a different default_max_qty than this file"
16 #endif
17
18
encode_repeated_message_error_C_x(zcbor_state_t * state,const struct message_error_C_x_ * input)19 static bool encode_repeated_message_error_C_x(
20 zcbor_state_t *state, const struct message_error_C_x_ *input)
21 {
22 zcbor_print("%s\r\n", __func__);
23
24 bool tmp_result = (((((*input)._message_error_C_x_choice == _message_error_C_x_bstr) ? ((zcbor_bstr_encode(state, (&(*input)._message_error_C_x_bstr))))
25 : (((*input)._message_error_C_x_choice == _message_error_C_x_int) ? ((zcbor_int32_encode(state, (&(*input)._message_error_C_x_int))))
26 : false))));
27
28 if (!tmp_result)
29 zcbor_trace();
30
31 return tmp_result;
32 }
33
encode_repeated_message_error_SUITES_R(zcbor_state_t * state,const struct message_error_SUITES_R_ * input)34 static bool encode_repeated_message_error_SUITES_R(
35 zcbor_state_t *state, const struct message_error_SUITES_R_ *input)
36 {
37 zcbor_print("%s\r\n", __func__);
38 bool int_res;
39
40 bool tmp_result = (((((*input)._message_error_SUITES_R_choice == _SUITES_R__supported) ? ((zcbor_list_start_encode(state, 10) && (int_res = (zcbor_multi_encode_minmax(2, 10, &(*input)._SUITES_R__supported_supported_count, (zcbor_encoder_t *)zcbor_int32_encode, state, (&(*input)._SUITES_R__supported_supported), sizeof(int32_t))), ((zcbor_list_end_encode(state, 10)) && int_res))))
41 : (((*input)._message_error_SUITES_R_choice == _message_error_SUITES_R_int) ? ((zcbor_int32_encode(state, (&(*input)._message_error_SUITES_R_int))))
42 : false))));
43
44 if (!tmp_result)
45 zcbor_trace();
46
47 return tmp_result;
48 }
49
encode_message_error(zcbor_state_t * state,const struct message_error * input)50 static bool encode_message_error(
51 zcbor_state_t *state, const struct message_error *input)
52 {
53 zcbor_print("%s\r\n", __func__);
54
55 bool tmp_result = (((zcbor_present_encode(&((*input)._message_error_C_x_present), (zcbor_encoder_t *)encode_repeated_message_error_C_x, state, (&(*input)._message_error_C_x))
56 && ((zcbor_tstr_encode(state, (&(*input)._message_error_DIAG_MSG))))
57 && zcbor_present_encode(&((*input)._message_error_SUITES_R_present), (zcbor_encoder_t *)encode_repeated_message_error_SUITES_R, state, (&(*input)._message_error_SUITES_R)))));
58
59 if (!tmp_result)
60 zcbor_trace();
61
62 return tmp_result;
63 }
64
65
66
cbor_encode_message_error(uint8_t * payload,size_t payload_len,const struct message_error * input,size_t * payload_len_out)67 bool cbor_encode_message_error(
68 uint8_t *payload, size_t payload_len,
69 const struct message_error *input,
70 size_t *payload_len_out)
71 {
72 zcbor_state_t states[4];
73
74 zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 3);
75
76 bool ret = encode_message_error(states, input);
77
78 if (ret && (payload_len_out != NULL)) {
79 *payload_len_out = MIN(payload_len,
80 (size_t)states[0].payload - (size_t)payload);
81 }
82
83 return ret;
84 }
85