-
Notifications
You must be signed in to change notification settings - Fork 1
/
decode_min.c
64 lines (46 loc) · 1.61 KB
/
decode_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
63
64
/*==============================================================================
decode_min.c -- Used for code size measurement of minimum size of decoder.
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_decode.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 decode functions so that only a minimum of the
decode library will be linked so the object code size of the smallest decoder
can be measured.
*/
int main(int argc, const char * argv[])
{
(void)argc; // Suppress unused warning
(void)argv; // Suppress unused warning
static const uint8_t min[] = {0x81, 0xf5};
// Decode it and see that is right
QCBORDecodeContext DC;
QCBORItem Item;
QCBORDecode_Init(&DC, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(min), QCBOR_DECODE_MODE_NORMAL);
// So first_symbol_x isn't dead-stripped
Item.uDataType = first_symbol_1();
Item.val.string.ptr = first_symbol_2;
QCBORDecode_GetNext(&DC, &Item);
if(Item.uDataType != QCBOR_TYPE_ARRAY) {
return 1;
}
QCBORDecode_GetNext(&DC, &Item);
if(Item.uDataType != QCBOR_TYPE_TRUE) {
return 2;
}
if(QCBORDecode_Finish(&DC)) {
return 3;
}
return 0;
}