Binn is a computer
data serialization format used mainly for application
data transfer
Data transmission and data reception or, more broadly, data communication or digital communications is the transfer and reception of data in the form of a digital bitstream or a digitized analog signal transmitted over a point-to-point o ...
. It stores
primitive data type
In computer science, primitive data types are a set of basic data types from which all other data types are constructed. Specifically it often refers to the limited set of data representations in use by a particular processor, which all compiled ...
s and
data structure
In computer science, a data structure is a data organization, management, and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the rel ...
s in a binary form.
[Binn README](_blank)
/ref>
Performance
The Binn format is designed to be compact and fast on readings. The elements are stored with their sizes to increase the read performance. The strings are null terminated so when read the library returns a pointer to them inside the buffer, avoiding memory allocation
Memory management is a form of resource management applied to computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and free it for reuse when ...
and data copying, an operation known as zero-copy
"Zero-copy" describes computer operations in which the CPU does not perform the task of copying data from one memory area to another or in which unnecessary data copies are avoided. This is frequently used to save CPU cycles and memory bandwid ...
.
Data types
Primitive data types:
* null
* boolean (true
and false
)
* integer (up to 64 bits signed or unsigned)
* floating point numbers (IEEE single/double precision)
* string
* blob (binary data)
* User defined
Containers:
* list
* map (numeric key associative array
In computer science, an associative array, map, symbol table, or dictionary is an abstract data type that stores a collection of (key, value) pairs, such that each possible key appears at most once in the collection. In mathematical terms an ...
)
* object (text key associative array)
Format
Binn structures consist of a list of ''elements''. Each element has a type that can be followed by the size, count of internal items, and the data itself:
boolean, null:
ype
int, float (storage: byte, word, dword or qword):
ypedata]
string, blob:
ypesize] ata
list, object, map:
ypesize] ountata
Example encoding
A JSON
JSON (JavaScript Object Notation, pronounced ; also ) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other s ...
data such as
is serialized in binn with the same size:
\xE2 // type = object (container)
\x11 // container total size
\x01 // items in the container (key/value pairs in this case)
\x05hello // field name
\xA0 // type = string
\x05world\x00 // field value (null terminated)
Example code
Writing to an object in C:
// create a new object
binn * obj = binn_object();
// add values to it
binn_object_set_int32(obj, "id", 123);
binn_object_set_str(obj, "name", "John");
binn_object_set_double(obj, "total", 2.55);
// send over the network or save to a file...
send(sock, binn_ptr(obj), binn_size(obj));
// release the buffer
binn_free(obj);
Reading from that object:
int id = binn_object_int32(obj, "id");
char * name = binn_object_str(obj, "name");
double total = binn_object_double(obj, "total");
See also
* JSON
JSON (JavaScript Object Notation, pronounced ; also ) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other s ...
* BSON
BSON () is a computer data interchange format. The name "BSON" is based on the term JSON and stands for "Binary JSON". It is a binary form for representing simple or complex data structures including associative arrays (also known as name-value ...
* UBJSON
* MessagePack
* Protocol Buffers
Protocol Buffers (Protobuf) is a free and open-source cross-platform data format used to serialize structured data. It is useful in developing programs to communicate with each other over a network or for storing data. The method involves an inte ...
* Comparison of data serialization formats
This is a comparison of data serialization formats, various ways to convert complex objects to sequences of bits. It does not include markup languages used exclusively as document file format
A document file format is a text or binary file for ...
Usages
LiteReplica
SQLite replication and point-in-time recovery tool.
EJDB2
Embeddable JSON Database engine C library.
GameAP
Game servers management panel.
References
{{Reflist
External links
Binn on GitHub
Data serialization formats