Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.ser.ion

High level Ion serialization API

struct IonSerializer(TapeHolder, string[] compiletimeSymbolTable, bool tableGC = true);
Ion serialization back-end
TapeHolder* tapeHolder;
IonSymbolTable!tableGC* runtimeTable;
int serdeTarget;
Mutable value used to choose format specidied or user-defined serialization specializations
size_t structBegin(size_t length = size_t.max);
void structEnd(size_t state);
alias listBegin = structBegin;
void listEnd(size_t state);
alias sexpBegin = listBegin;
void sexpEnd(size_t state);
alias stringBegin = structBegin;
void putStringPart(scope const(char)[] str);
Puts string part. The implementation allows to split string unicode points.
void stringEnd(size_t state);
size_t annotationsBegin();
void annotationsEnd(size_t state);
alias annotationWrapperBegin = structBegin;
void annotationWrapperEnd(size_t state);
void putCompiletimeKey(string key)();
alias putCompiletimeAnnotation = putCompiletimeKey;
void putKey()(scope const char[] key);
alias putAnnotation = putKey;
void putKeyId(T)(const T id)
if (__traits(isUnsigned, T));
alias putAnnotationId = putKeyId;
void putSymbolId(size_t id);
void putSymbol(scope const char[] key);
void putValue(Num)(const Num num)
if (isNumeric!Num && !is(Num == enum));
void putValue(W, WordEndian endian)(BigIntView!(W, endian) view);
void putValue(size_t size)(auto const ref BigInt!size num);
void putValue(size_t size)(auto const ref Decimal!size num);
void putValue(typeof(null));
void putNull(IonTypeCode code);
void putValue(bool b);
void putValue(scope const char[] value);
void putValue(Clob value);
void putValue(Blob value);
void putValue(Timestamp value);
void elemBegin();
alias sexpElemBegin = elemBegin;
void nextTopLevelValue();
immutable(ubyte)[] serializeIon(T)(auto ref T value, int serdeTarget = SerdeTarget.ion);
Ion serialization function.
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,
];

assert (s.serializeIon == data);
enum staticData = s.serializeIon;
static assert (staticData == data);
Examples:
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);
template ionSerializer(string sep = "")
Creates Ion serialization back-end. Use sep equal to "\t" or " " for pretty formatting.
auto ionSerializer(Appender)(return Appender* appender, int serdeTarget = serdeTarget.ion);