json-gen-c  0.1.5
json-gen-c generate C code for json manipulation
cbor_codec.h
Go to the documentation of this file.
1
9#ifndef CBOR_CODEC_H
10#define CBOR_CODEC_H
11
12#include <stdint.h>
13#include <stddef.h>
14
15/* ── CBOR major types (high 3 bits of initial byte) ─────────────────── */
16
17#define CB_MAJOR_UINT 0 /* Major type 0: unsigned integer */
18#define CB_MAJOR_NINT 1 /* Major type 1: negative integer */
19#define CB_MAJOR_BSTR 2 /* Major type 2: byte string */
20#define CB_MAJOR_TSTR 3 /* Major type 3: text string (UTF-8) */
21#define CB_MAJOR_ARRAY 4 /* Major type 4: array */
22#define CB_MAJOR_MAP 5 /* Major type 5: map */
23#define CB_MAJOR_TAG 6 /* Major type 6: semantic tag */
24#define CB_MAJOR_SIMPLE 7 /* Major type 7: simple/float */
25
26/* Initial byte = (major << 5) | additional_info */
27#define CB_INITIAL(major, ai) (((major) << 5) | (ai))
28
29/* ── Additional information values ──────────────────────────────────── */
30
31#define CB_AI_1BYTE 24 /* Next 1 byte is the value/length */
32#define CB_AI_2BYTE 25 /* Next 2 bytes */
33#define CB_AI_4BYTE 26 /* Next 4 bytes */
34#define CB_AI_8BYTE 27 /* Next 8 bytes */
35
36/* ── Simple values (major type 7) ───────────────────────────────────── */
37
38#define CB_FALSE CB_INITIAL(7, 20) /* 0xf4 */
39#define CB_TRUE CB_INITIAL(7, 21) /* 0xf5 */
40#define CB_NULL CB_INITIAL(7, 22) /* 0xf6 */
41#define CB_UNDEFINED CB_INITIAL(7, 23) /* 0xf7 */
42
43/* ── Float markers (major type 7) ───────────────────────────────────── */
44
45#define CB_FLOAT16 CB_INITIAL(7, 25) /* 0xf9 — half-precision */
46#define CB_FLOAT32 CB_INITIAL(7, 26) /* 0xfa */
47#define CB_FLOAT64 CB_INITIAL(7, 27) /* 0xfb */
48
49/* ── Reader context ─────────────────────────────────────────────────── */
50
51struct cb_reader {
52 const unsigned char *data;
53 size_t len;
54 size_t pos;
55};
56
57#endif /* CBOR_CODEC_H */
Definition cbor_codec.h:51
position of string
Definition struct_parse.h:175