serializeIon

Ion serialization function.

  1. immutable(ubyte)[] serializeIon(T value, int serdeTarget)
    immutable(ubyte)[]
    serializeIon
    (
    T
    )
    (
    auto ref T value
    ,
    int serdeTarget = SerdeTarget.ion
    )
  2. void serializeIon(Appender appender, T value, int serdeTarget)

Examples

static struct S
{
    string s;
    double aaaa;
    int bbbb;
}

enum s = S("str", 1.23, 123);

static immutable ubyte[] data = [
    0xe0, 0x01, 0x00, 0xea, 0xee, 0x92, 0x81, 0x83,
    0xde, 0x8e, 0x87, 0xbc, 0x81, 0x73, 0x84, 0x61,
    0x61, 0x61, 0x61, 0x84, 0x62, 0x62, 0x62, 0x62,
    0xde, 0x92, 0x8a, 0x83, 0x73, 0x74, 0x72, 0x8b,
    0x48, 0x3f, 0xf3, 0xae, 0x14, 0x7a, 0xe1, 0x47,
    0xae, 0x8c, 0x21, 0x7b,
];

import mir.test;
s.serializeIon.should == data;
enum staticData = s.serializeIon;
static assert (staticData == data);
import mir.serde: SerdeTarget;
static immutable ubyte[] binaryDataAB = [0xe0, 0x01, 0x00, 0xea, 0xe9, 0x81, 0x83, 0xd6, 0x87, 0xb4, 0x81, 0x61, 0x81, 0x62, 0xd6, 0x8a, 0x21, 0x01, 0x8b, 0x21, 0x02];
static immutable ubyte[] binaryDataBA = [0xe0, 0x01, 0x00, 0xea, 0xe9, 0x81, 0x83, 0xd6, 0x87, 0xb4, 0x81, 0x62, 0x81, 0x61, 0xd6, 0x8a, 0x21, 0x02, 0x8b, 0x21, 0x01];
int[string] table = ["a" : 1, "b" : 2];
auto data = table.serializeIon(SerdeTarget.ion);
assert(data == binaryDataAB || data == binaryDataBA);

Meta