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_data_2.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_data_2_C_I(zcbor_state_t * state,const struct data_2_C_I_ * input)19 static bool encode_repeated_data_2_C_I(
20 		zcbor_state_t *state, const struct data_2_C_I_ *input)
21 {
22 	zcbor_print("%s\r\n", __func__);
23 
24 	bool tmp_result = (((((*input)._data_2_C_I_choice == _data_2_C_I_int) ? ((zcbor_int32_encode(state, (&(*input)._data_2_C_I_int))))
25 	: (((*input)._data_2_C_I_choice == _data_2_C_I_bstr) ? ((zcbor_bstr_encode(state, (&(*input)._data_2_C_I_bstr))))
26 	: false))));
27 
28 	if (!tmp_result)
29 		zcbor_trace();
30 
31 	return tmp_result;
32 }
33 
encode_data_2(zcbor_state_t * state,const struct data_2 * input)34 static bool encode_data_2(
35 		zcbor_state_t *state, const struct data_2 *input)
36 {
37 	zcbor_print("%s\r\n", __func__);
38 
39 	bool tmp_result = (((zcbor_present_encode(&((*input)._data_2_C_I_present), (zcbor_encoder_t *)encode_repeated_data_2_C_I, state, (&(*input)._data_2_C_I))
40 	&& ((zcbor_bstr_encode(state, (&(*input)._data_2_G_Y))))
41 	&& ((((*input)._data_2_C_R_choice == _data_2_C_R_int) ? ((zcbor_int32_encode(state, (&(*input)._data_2_C_R_int))))
42 	: (((*input)._data_2_C_R_choice == _data_2_C_R_bstr) ? ((zcbor_bstr_encode(state, (&(*input)._data_2_C_R_bstr))))
43 	: false))))));
44 
45 	if (!tmp_result)
46 		zcbor_trace();
47 
48 	return tmp_result;
49 }
50 
51 
52 
cbor_encode_data_2(uint8_t * payload,size_t payload_len,const struct data_2 * input,size_t * payload_len_out)53 bool cbor_encode_data_2(
54 		uint8_t *payload, size_t payload_len,
55 		const struct data_2 *input,
56 		size_t *payload_len_out)
57 {
58 	zcbor_state_t states[3];
59 
60 	zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 3);
61 
62 	bool ret = encode_data_2(states, input);
63 
64 	if (ret && (payload_len_out != NULL)) {
65 		*payload_len_out = MIN(payload_len,
66 				(size_t)states[0].payload - (size_t)payload);
67 	}
68 
69 	return ret;
70 }
71