Concise Binary Object Representation (CBOR) binary serialization library.
BBaz via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Fri Dec 19 14:33:56 PST 2014
On Friday, 19 December 2014 at 18:26:26 UTC, MrSmith wrote:
> 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!
Do you know OGDL ?
http://ogdl.org/
It's currently the more 'appealing' thing to me for serialization.
More information about the Digitalmars-d-announce
mailing list