forked from laurencelundblade/qdv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_max.c
More file actions
73 lines (55 loc) · 2.07 KB
/
encode_max.c
File metadata and controls
73 lines (55 loc) · 2.07 KB
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
64
65
66
67
68
69
70
71
72
73
/*==============================================================================
encode_max.c -- Used for code size measurement of max 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 enough encode functions so that everything in the encode
library will be linked so the object code size of the full 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];
UsefulBufC x;
// Very simple CBOR, a map with one boolean that is true in it
QCBOREncodeContext EC;
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(pBuf));
QCBOREncode_OpenArray(&EC);
QCBOREncode_OpenMap(&EC);
QCBOREncode_AddInt64ToMapN(&EC, 66, -999999999);
QCBOREncode_AddUInt64ToMapN(&EC, 66, -999999999);
QCBOREncode_BstrWrap(&EC);
QCBOREncode_AddTag(&EC, 99);
QCBOREncode_AddFloatNoPreferred(&EC, 99.999f);
QCBOREncode_AddDoubleToMapN(&EC, 66, 99.9999999);
QCBOREncode_CloseBstrWrap2(&EC, true, &x);
QCBOREncode_AddSZStringToMapN(&EC, 888, "hi there");
QCBOREncode_OpenArrayIndefiniteLength(&EC);
QCBOREncode_AddBigFloatToMapN(&EC, 10, 10, 10);
QCBOREncode_CloseArrayIndefiniteLength(&EC);
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;
}