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_1.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_message_1(zcbor_state_t * state,const struct message_1 * input)19 static bool encode_message_1(
20 		zcbor_state_t *state, const struct message_1 *input)
21 {
22 	zcbor_print("%s\r\n", __func__);
23 	bool int_res;
24 
25 	bool tmp_result = (((((zcbor_int32_encode(state, (&(*input)._message_1_METHOD))))
26 	&& ((((*input)._message_1_SUITES_I_choice == _SUITES_I__suite) ? ((zcbor_list_start_encode(state, 10) && (int_res = (zcbor_multi_encode_minmax(2, 10, &(*input)._SUITES_I__suite_suite_count, (zcbor_encoder_t *)zcbor_int32_encode, state, (&(*input)._SUITES_I__suite_suite), sizeof(int32_t))), ((zcbor_list_end_encode(state, 10)) && int_res))))
27 	: (((*input)._message_1_SUITES_I_choice == _message_1_SUITES_I_int) ? ((zcbor_int32_encode(state, (&(*input)._message_1_SUITES_I_int))))
28 	: false)))
29 	&& ((zcbor_bstr_encode(state, (&(*input)._message_1_G_X))))
30 	&& ((((*input)._message_1_C_I_choice == _message_1_C_I_int) ? ((zcbor_int32_encode(state, (&(*input)._message_1_C_I_int))))
31 	: (((*input)._message_1_C_I_choice == _message_1_C_I_bstr) ? ((zcbor_bstr_encode(state, (&(*input)._message_1_C_I_bstr))))
32 	: false)))
33 	&& zcbor_present_encode(&((*input)._message_1_ead_1_present), (zcbor_encoder_t *)zcbor_bstr_encode, state, (&(*input)._message_1_ead_1)))));
34 
35 	if (!tmp_result)
36 		zcbor_trace();
37 
38 	return tmp_result;
39 }
40 
41 
42 
cbor_encode_message_1(uint8_t * payload,size_t payload_len,const struct message_1 * input,size_t * payload_len_out)43 bool cbor_encode_message_1(
44 		uint8_t *payload, size_t payload_len,
45 		const struct message_1 *input,
46 		size_t *payload_len_out)
47 {
48 	zcbor_state_t states[4];
49 
50 	zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 5);
51 
52 	bool ret = encode_message_1(states, input);
53 
54 	if (ret && (payload_len_out != NULL)) {
55 		*payload_len_out = MIN(payload_len,
56 				(size_t)states[0].payload - (size_t)payload);
57 	}
58 
59 	return ret;
60 }
61