Concise Binary Object Representation (CBOR) binary serialization library.

MrSmith via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Fri Dec 19 10:26:25 PST 2014


The Concise Binary Object Representation (CBOR) is a data format
whose design goals include the possibility of extremely small code
size, fairly small message size, and extensibility without the 
need
for version negotiation.  These design goals make it different 
from
earlier binary serializations such as ASN.1 and MessagePack.

Here is more info about format: http://cbor.io/

You can easily encode and decode things like built-in types, 
arrays, hash-maps, structs, tuples, classes, strings and raw 
arrays (ubyte[]).

Here is some simple code:

     import cbor;

     struct Inner
     {
         int[] array;
         string someText;
     }

     struct Test
     {
         ubyte b;
         short s;
         uint i;
         long l;
         float f;
         double d;
         ubyte[] arr;
         string str;
         Inner inner;

         void fun(){} // not encoded
         void* pointer; // not encoded
         int* numPointer; // not encoded
     }

     ubyte[1024] buffer;
     size_t encodedSize;

     Test test = Test(42, -120, 111111, -123456789, 0.1234, 
-0.987654,
         cast(ubyte[])[1,2,3,4,5,6,7,8], "It is a test string",
         Inner([1,2,3,4,5], "Test of inner struct"));

     encodedSize = encodeCborArray(buffer[], test);

     // ubyte[] and string types are slices of input ubyte[].
     Test result = decodeCborSingle!Test(buffer[0..encodedSize]);

     // decodeCborSingleDup can be used to auto-dup those types.

     assert(test == result);

Here is github link: https://github.com/MrSmith33/cbor-d
Destroy!


More information about the Digitalmars-d-announce mailing list