HiBON + HiRPC

Fast, serializable, hash-invariant data format

HiBON is a data format inspired by BSON and developed for the Tagion network.

It’s a serializable binary format which is strongly typed and defines explicit ordering to achieve hash-invariance.
It’s minimal and designed to be quick to encode, decode and verify.

Hash invariant Binary Object Notation (HiBON)

HiBON is a streamable data format which is able to contain common binary data types. Pronounced ‘Haibon’ Description of the binary package format Package size A data package is defined as with a length in bytes appended string of bytes. Length field Data unsigned LEB128 byte array The length field is defined by a unsigned LEB128. Basic Types The HiBON binary format describe here in pseudo-BNF format. Type name Type description int signed 32 integer long signed 64 integer uint unsigned 32 integer ulong unsigned 64 integer float 32-bit IEEE 754-2008 binary floating point double 64-bit IEEE 754-2008 binary floating point utf8* is defined as a string of characters in UTF-8 format char* is defined as a string of characters in ASCII format byte* is defined as a string of bytes i32 signed 32 integer in leb128 format i64 signed 32 integer in leb128 format u32 unsigned 32 integer in leb128 format u64 unsigned 64 integer in leb128 format f32 float in little endian format f64 double in little endian format len is a length file as u32 except the ‘\x00’ is not allowed null is defined as ‘\x00’ document ::= null | len list // len in bytes contained in the list // null value means the the document is empty list ::= element list key ::= key_index | key_string // Member key either as a u32 or text element ::= // TYPE key value FLOAT64 key f64 | FLOAT32 key f32 | STRING key string | DOCUMENT key document | BINARY key binary | BOOLEAN key ('\x00'|'\x01') | TIME key i64 // Standard Time counted as the total 100nsecs from midnight, // January 1st, 1 A....

LEB128 Integer encoding

The LEB128 https://en.wikipedia.org/wiki/LEB128 format is used store the integer values in the HiBON stream. D encoding & decoding samples Sample to encode to LEB128 in D @safe immutable(ubyte[]) encode(T)(const T v) pure if(isUnsigned!T && isIntegral!T) { ubyte[T.sizeof+2] data; alias BaseT=TypedefType!T; BaseT value=cast(BaseT)v; foreach(i, ref d; data) { d = value & 0x7f; value >>= 7; if (value == 0) { return data[0..i+1].idup; } d |= 0x80; } assert(0); } @safe immutable(ubyte[]) encode(T)(const T v) pure if(isSigned!...

JSON Interchange Format (HiBONJSON)

Converting between HiBON and JSON To secure than HiBON is hash invariant when HiBON is converted back and forth between HiBON and JSON. The JSON must flow the format described below. A HiBON object must be generated as a JSON object and a HiBON array must be generated as a JSON object. HiBON data types must be generated as a JSON array with two element where the element index 0 is HiBON type as a string and element index 1 is the contains the value....

Remote Procedure Calls (HiRPC)

HiBON Remote Procedure Call (HiRPC) HiRPC is a RPC which can including digital signatures and it is base on HiBON data format. Structure of HiRPC { $@ : 'HiPRC', $sign : <bin>, // Optional $pkey : <bin>, // Optional $msg : { id : <uint>, method : <string>, // Name of the method params : <Document>, // Optional } } The member sign is the $sign hirpc object and $pkey is the public-key which also include a $sign schema code in the genetic package....

Schema Types (HiBONRecord)  [draft]

HiBON Record ⚠️ This Document is unfinished HiBON Records Keys with prefix with # is a hash element, Only one hash element is allowed in the HiBON object. Keys with prefix with $ is a parameter. The key $@ reseved for the as a type-name all types starting with $@ is reseved for internal use.

API Examples

Usage examples in D-lang For the full hibon D api documentation see HiBON ddoc Object interface // Create an hibon auto hibon = new HiBON; // Asign something to a key hibon["hai"] = "bon"; // Create a serialized `Document` buffer hibon.toDoc; Lazy serialized documents // Where data is some ubyte[] received from the network or serialized directly from a hibon // Creates a handler for the serialized data auto doc = Document(data) // Get a string value from the buffer string decoded = doc["hai"]....