-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbor.h
More file actions
80 lines (60 loc) · 1.75 KB
/
cbor.h
File metadata and controls
80 lines (60 loc) · 1.75 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
74
75
76
77
78
79
80
#ifndef TINY_CBOR_CBOR_H
#define TINY_CBOR_CBOR_H
#include <stdint.h>
#include <stdio.h>
#define PB_BYTES_ARRAY_T(n) struct { uint8_t size; uint8_t bytes[n]; }
typedef uint_least8_t pb_size_t;
typedef unsigned char u_int8_t;
typedef PB_BYTES_ARRAY_T(512) cbor_bytes;
typedef enum {
MT_INVALID = -1,
MT_UNSIGNED = 0,
MT_NEGATIVE = 1,
MT_BYTES = 2,
MT_TEXT = 3,
MT_ARRAY = 4,
MT_MAP = 5,
MT_TAG = 6,
MT_PRIMITIVE = 7,
MT_INDEFINITE = 8,
MT_RAW = 9
} MajorType;
typedef enum {
DIRECT = -1,
ONE_BYTE = 24,
TWO_BYTES = 25,
FOUR_BYTES = 26,
EIGHT_BYTES = 27,
RESERVED = 28,
INDEFINITE = 31
} AdditionalInformation;
typedef struct cborMapItem {
char key[128];
struct cborItem *value;
} cborMapItem;
typedef struct cborItem {
MajorType type;
/** CBOR_BYTES */
cbor_bytes bytes;
/** CBOR_TEXT */
char str[512];
/** CBOR_INT */
long uint;
/** CBOR_TAG*/
long tag;
/** Number of children.*/
int length;
struct cborItem *firstItem;
struct cborItem *nextItem;
} cborItem;
void cbor_encode_indefinite_length_array(u_int8_t *new_bytes, size_t *written, cborItem * parent);
int cbor_encode(u_int8_t *new_bytes, size_t *written, cborItem *item);
void cbor_create_integer(cborItem *item, long value);
void cbor_create_tag(cborItem *item, uint8_t *value, size_t value_size, long tag);
void cbor_create_bytes(cborItem *item, uint8_t *bytes, size_t byte_size);
void cbor_create_raw(cborItem *item, uint8_t *bytes, size_t byte_size);
void cbor_create_array(cborItem *parent);
void cbor_infinite_create_array(cborItem * parent);
void cbor_add_item_to_array(cborItem *parent, cborItem *newItem);
void cbor_create_map(cborItem *parent);
#endif //TINY_CBOR_CBOR_H