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:

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:

Reply via email to