@@ -54,7 +54,19 @@ about 0.0015%. The type is `binary_fuse16_t` and you may use it with
5454functions such as `binary_fuse16_allocate`, `binary_fuse16_populate`,
5555`binary_fuse8_contain` and `binary_fuse8_free`.
5656
57- You may serialize the data as follows:
57+ For serialization, there is a choice between an unpacked and a packed format.
58+
59+ The unpacked format is roughly of the same size as in-core data, but uses most
60+ efficient memory copy operations.
61+
62+ The packed format avoids storing zero bytes and is considered near optimal (it
63+ can not be compressed further by zlib and its required space is very close to
64+ the theoretical lower limit), but it needs to copy individual words, so it
65+ should be expected to be somewhat slower.
66+
67+ The two formats use slightly different APIs.
68+
69+ You may serialize and deserialize in unpacked format as follows:
5870
5971```C
6072 size_t buffer_size = binary_fuse16_serialization_bytes(&filter);
@@ -65,9 +77,31 @@ You may serialize the data as follows:
6577 free(buffer);
6678```
6779
68- The serialization does not handle endianess: it is expected that you will serialize
69- and deserialize on the little endian systems. (Big endian systems are vanishingly rare.)
80+ To serialize and deserialize in packed format, use the ` _pack_bytes() ` ,
81+ ` _pack() ` and ` _unpack() ` functions. The latter two have an additional ` size_t `
82+ argument for the buffer length. ` _pack() ` can be used with a buffer of arbitrary
83+ size, it returns the used space if serialization fit into the buffer or 0
84+ otherwise.
85+
86+ For example:
87+
88+ ``` C
89+ size_t buffer_size = binary_fuse16_pack_bytes(&filter);
90+ char *buffer = (char *)malloc(buffer_size);
91+ if (binary_fuse16_pack(&filter, buffer, buffer_size) != buffer_size) {
92+ printf ("pack failed\n");
93+ free(buffer);
94+ return;
95+ }
96+ binary_fuse16_free (&filter);
97+ if (! binary_fuse16_unpack(&filter, buffer, buffer_size)) {
98+ printf("unpack failed\n");
99+ }
100+ free (buffer);
101+ ```
70102
103+ Either serialization does not handle endianess changes: it is expected that you
104+ serialize and deserialize with equal byte order.
71105
72106## C++ wrapper
73107
0 commit comments