Avro

From Organic Design wiki

Apache Avro is a language neutral, data serialization framework similar that can serialize data into binary very efficiently.

Install

C

First ensure you have the jansson package installed:

sudo apt-get install libjansson-dev

Then you can download the Avro C package from the download page.

Follow the instructions inside the INSTALL file to install.

Then to compile your c code:

gcc -I/include -c -o main.o main.c
gcc -o main main.o /lib/libavro.so

Signed Integer

Avro stores 32 bit integers using ZigZag and variable integer encoding allowing for minimal storage of integers.

Unsigned Integer

Avro does not support unsigned integers by default but they can be implemented as a logical type. To create the unsigned encoding you will need to decode the ZigZag encoding before passing the value:

(num >>> 1) ^ -(num & 1)

Then when retrieving the data encode it with the ZigZag:

(num << 1) ^ (num >> 31)

This allows minimal storage of unsigned integers. This works because you reverse the encoding before Avro encodes it leaving the value unchanged and when reading it you reverse the decoding of the value by encoding it.

See Also