forked from NordicSemiconductor/zcbor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pet_encode.c
63 lines (51 loc) · 2.15 KB
/
pet_encode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*
* Generated using zcbor version 0.9.99
* https://github.com/NordicSemiconductor/zcbor
* Generated with a --default-max-qty of 3
*/
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "zcbor_encode.h"
#include "pet_encode.h"
#include "zcbor_print.h"
#if DEFAULT_MAX_QTY != 3
#error "The type file was generated with a different default_max_qty than this file"
#endif
#define log_result(state, result, func) do { \
if (!result) { \
zcbor_trace_file(state); \
zcbor_log("%s error: %s\r\n", func, zcbor_error_str(zcbor_peek_error(state))); \
} else { \
zcbor_log("%s success\r\n", func); \
} \
} while(0)
static bool encode_Pet(zcbor_state_t *state, const struct Pet *input);
static bool encode_Pet(
zcbor_state_t *state, const struct Pet *input)
{
zcbor_log("%s\r\n", __func__);
bool res = (((zcbor_list_start_encode(state, 3) && ((((zcbor_list_start_encode(state, 3) && ((zcbor_multi_encode_minmax(1, 3, &(*input).names_count, (zcbor_encoder_t *)zcbor_tstr_encode, state, (*&(*input).names), sizeof(struct zcbor_string))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 3)))
&& (((((((*input).birthday.len == 8)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))
&& (zcbor_bstr_encode(state, (&(*input).birthday))))
&& ((((*input).species_choice == Pet_species_cat_c) ? ((zcbor_uint32_put(state, (1))))
: (((*input).species_choice == Pet_species_dog_c) ? ((zcbor_uint32_put(state, (2))))
: (((*input).species_choice == Pet_species_other_c) ? ((zcbor_uint32_put(state, (3))))
: false))))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 3))));
log_result(state, res, __func__);
return res;
}
int cbor_encode_Pet(
uint8_t *payload, size_t payload_len,
const struct Pet *input,
size_t *payload_len_out)
{
zcbor_state_t states[4];
return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states,
(zcbor_decoder_t *)encode_Pet, sizeof(states) / sizeof(zcbor_state_t), 1);
}