forked from laurencelundblade/qdv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode_min.c
62 lines (44 loc) · 1.6 KB
/
encode_min.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
/*==============================================================================
encode_min.c -- Used for code size measurement of minimum size of encoder.
Copyright (c) 2020, Laurence Lundblade. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
See BSD-3-Clause license in README.md
=============================================================================*/
#include "qcbor/qcbor_encode.h"
/* These two symbols hopefully appear at the start and
allow use of nm(1) to list symbols in order so the
sizes of the functions can be computed relative to the
previous symbol
*/
int first_symbol_1() {
return 7;
}
static const uint8_t first_symbol_2[] = {0x55, 0x66};
/*
This calls just the basic encode functions so that only a minimum of the
encode library will be linked so the object code size of the smallest encoder
can be measured.
*/
int main(int argc, const char * argv[])
{
(void)argc; // Suppress unused warning
(void)argv; // Suppress unused warning
uint8_t pBuf[300];
QCBOREncodeContext EC;
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(pBuf));
QCBOREncode_OpenArray(&EC);
QCBOREncode_OpenMap(&EC);
QCBOREncode_AddInt64ToMapN(&EC, 66, -999999999);
QCBOREncode_AddSZStringToMapN(&EC, 888, "hi there");
QCBOREncode_AddBoolToMapN(&EC, 66, true);
QCBOREncode_CloseMap(&EC);
QCBOREncode_CloseArray(&EC);
UsefulBufC Encoded;
// So first_symbol_x is not dead-stripped */
Encoded.len = first_symbol_1();
Encoded.ptr = first_symbol_2;
if(QCBOREncode_Finish(&EC, &Encoded)) {
return -1;
}
return 0;
}