💾 Archived View for gmi.noulin.net › markdown › netSerial_README.md captured on 2023-07-10 at 18:18:48.
-=-=-=-=-=-=-
# Sheepy This is a sheepy package for [sheepy](https://spartatek.se/r/sheepy/file/README.md.html) and using [libsheepy](https://spartatek.se/r/libsheepy/file/README.md.html) # netSerial netSerial is a serializer/deserializer for JSON data structures that has compact binary format. In general, it gives smaller bitstreams than JSON strings and smallJson serializer bitstream. The netSerial serializer is in average 1.5 times slower than the smallJson serializer. # Usage Install with spm: `spm install netSerial` Include netSerial: `#include "shpPackages/netSerial/netSerial.h"`, then:
// create a netSerial object:
createNetSerial(n);
// create a JSON
parseG(&n, "[3,270,-86942]");
smallBytest *bitstream = serialG(&n);
# Encoding Data types are encoded on 4 bits: - undefined - bool - dict - double - varint - string - array - bytes = faststring - packed dict - packed double - packed varint - packed string - packed array - packed bytes - dict - all elements have same type - array - all elements have same type Integers are encoded as varint (n <<1 ^ n >> 63, see [protobuf](https://developers.google.com/protocol-buffers/docs/encoding)) and lengths (array, dictionary) are encoded as varuint. The integer _150_ is encoded as `0xc4 0x25`. - 0xc_4_ is integer type - 0x_c_4 are the first 3 bits in 150, bit 7 is set so next byte represents the 7 next bits in 150 - _0x25_ are last bits in 150 The encoding of `[3,270,-86942]` gives:
0x4f - uniform array of varint elements
0x03 - 3 elements
0x06 - int 3
0x9c 0x04 - int 270
0xbb 0xce 0x0a - int -86942
The arrays have 2 variants: normal and uniform. Normal arrays have elements of any types whereas uniform arrays have only one type of elements. For example, `[null,null,null]` is a uniform array of undefined values, encoded as:
0x0f - uniform array of undefined(null) elements
0x03 - 3 elements
undefined is a type without data, only the element count is needed to represent an array of null elements. The bool type is encoded in 4bits type + 1 bit data and is packed by default:
{"sdf":true,"0":null,"1":null,"2":true,"3":true}
0x52 - dictionary with 5 elements
0x73 0x64 0x66 0x00 - "sdf" string
0x71 - bool type and bool data for bool 1,2 and 3 (true)
0x30 0x00 - "0" string
0x00 - undefined 1 and 2
0x31 0x00 - "1" string
0x32 0x00 - "2" string
0x11 - bool type 2 and 3
0x33 0x00 - "3" string
Encoding a dictionary and an array:
{"a":[3,270,-86942]}
0xfe - uniform dictionary of uniform arrays
0x01 - 1 element
0x61 0x00 - "a" string
0x34 - int type and 3 elements
0x06 - int 3
0x9c 0x04 - int 270
0xbb 0xce 0x0a - int -86942
-