ProductPromotion
Logo

C Programming

made by https://0x3d.site

GitHub - liteserver/binn: Binary Serialization
Binary Serialization. Contribute to liteserver/binn development by creating an account on GitHub.
Visit Site

GitHub - liteserver/binn: Binary Serialization

GitHub - liteserver/binn: Binary Serialization

Binn

Build Status Tests Stable

Binn is a binary data serialization format designed to be compact, fast and easy to use.

Performance

The elements are stored with their sizes to increase the read performance.

The library uses zero-copy when reading strings, blobs and containers.

The strings are null terminated so when read the library returns a pointer to them inside the buffer, avoiding memory allocation and data copying.

Data Types

The Binn format supports all these:

Primitive data types:

  • null
  • boolean (true and false)
  • integer (up to 64 bits signed or unsigned)
  • floating point numbers (IEEE single and double precision)
  • string
  • blob (binary data)
  • user defined

Containers:

  • list
  • map (numeric key associative array)
  • object (text key associative array)

Format

The elements are stored in this way:

Example Structure

A json data such as {"hello":"world"} is serialized in binn as:

You can check the complete specification

Usage Example

Writing

binn *obj;

// create a new object
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

int id;
char *name;
double total;

id = binn_object_int32(obj, "id");
name = binn_object_str(obj, "name");
total = binn_object_double(obj, "total");

More examples

You can find more usage examples here and in the examples folder

Other Implementations

Feel free to make a wrapper for your preferred language. Then inform us so we can list it here.

How to use

  1. Including the binn.c file in your project; or
  2. Including the static library in your project; or
  3. Linking to the binn library:

On Linux and MacOSX:

gcc myapp.c -lbinn

On Windows:

Include the binn-3.0.lib in your MSVC project or use MinGW:

gcc myapp.c -lbinn-3.0

Compiling the Library

On Linux and MacOSX:

git clone https://github.com/liteserver/binn
cd binn
make
sudo make install

It will create the file libbinn.so.3.0 on Linux and libbinn.3.dylib on MacOSX

On Windows:

Use the included Visual Studio project in the src/win32 folder or compile it using MinGW:

git clone https://github.com/liteserver/binn
cd binn
make

Both will create the file binn-3.0.dll

Static library

To generate a static library:

make static

It will create the file libbinn.a

On Android:

Check for pre-compiled binaries in the android-binn-native project

Regression Tests

On Linux, MacOSX and Windows (MinGW):

cd binn
make test

On Windows (Visual Studio):

Use the included project in the test/win32 folder

Reliability

The current version (3.0) is stable and production ready

As it is cross-platform, data can be transferred between little-endian and big-endian devices

Security

For performance reasons, the read functions do not fully check the integrity of the buffer

So it is highly recommended to check the buffer integrity once data is received from the network or read from a file

Apart from checking for a valid buffer, we recommend to discard messages smaller than 4 bytes, despite messages with just 3 bytes (an empty list) being valid. This is due to a bug that was introduced when making the serialization smaller.

Here is an example of check to use:

void on_new_message(char *msg, int size) {
  /* discard invalid messages */
  if (size < 4) return;
  if (binn_is_valid_ex(msg, NULL, NULL, &size) == FALSE) return;
  /* the message is valid */
  ...

Licence

Apache 2.0

Contact

Questions, suggestions, support: contact AT litereplica DOT io

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory