summaryrefslogtreecommitdiff
path: root/vere/pkg/ur/serial.h
blob: 3044c4b5980be6dcf54ef6eb0401d6b1d0b88778 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/// @file

#ifndef UR_SERIAL_H
#define UR_SERIAL_H

#include <inttypes.h>

#include "bitstream.h"
#include "defs.h"
#include "hashcons.h"

/*
**  bit-wise serialization of a noun into a byte-buffer.
**  supports up to 64-bits of bit-addressed output (nearly 2 EiB).
**  (as this is an impractical volume data, cursor overflow is not checked.)
**
**  jam_with* api factors out stack/dict (re)allocation,
**  for better performance inside hot loops.
**
*/

typedef struct ur_jam_s ur_jam_t;

uint64_t
ur_jam_unsafe(ur_root_t      *r,
              ur_nref       ref,
              ur_dict64_t *dict,
              uint64_t     *len,
              uint8_t     **byt);

uint64_t
ur_jam(ur_root_t  *r,
       ur_nref   ref,
       uint64_t *len,
       uint8_t **byt);

ur_jam_t*
ur_jam_init_with(ur_root_t    *r,
                 uint64_t d_prev,
                 uint64_t d_size,
                 uint32_t s_prev,
                 uint32_t s_size);

ur_jam_t*
ur_jam_init(ur_root_t *r);

uint64_t
ur_jam_with(ur_jam_t   *j,
            ur_nref   ref,
            uint64_t *len,
            uint8_t **byt);
void
ur_jam_done(ur_jam_t *j);

/*
**  bitwise deserialization of a byte-buffer into a noun.
**  supports up to 62-bits of bit-addressed input (511 PiB).
**  returns [ur_cue_good] on success.
**
**  cue_with factors out stack/dict (re)allocation,
**  for better performance of hot loops.
**
**  cue_test does not allocate nouns, but merely parses the input;
**  cue_test_with* api factors out stack/dict (re)allocation,
**  for better performance of repeated tests.
**
*/

typedef struct ur_cue_test_s ur_cue_test_t;
typedef struct ur_cue_s      ur_cue_t;

ur_cue_res_e
ur_cue(ur_root_t *r, uint64_t len, const uint8_t *byt, ur_nref *out);

ur_cue_t*
ur_cue_init_with(ur_root_t    *r,
                 uint64_t d_prev,
                 uint64_t d_size,
                 uint32_t s_prev,
                 uint32_t s_size);

ur_cue_t*
ur_cue_init(ur_root_t *r);

ur_cue_res_e
ur_cue_with(ur_cue_t        *c,
            uint64_t       len,
            const uint8_t *byt,
            ur_nref       *out);

void
ur_cue_done(ur_cue_t *c);

ur_bool_t
ur_cue_test(uint64_t len, const uint8_t *byt);

ur_cue_test_t*
ur_cue_test_init_with(uint64_t d_prev,
                      uint64_t d_size,
                      uint32_t s_prev,
                      uint32_t s_size);

ur_cue_test_t*
ur_cue_test_init(void);

ur_bool_t
ur_cue_test_with(ur_cue_test_t   *t,
                 uint64_t       len,
                 const uint8_t *byt);

void
ur_cue_test_done(ur_cue_test_t *t);

#endif /* ifndef UR_SERIAL_H */