textSerializer

Creates Ion serialization back-end. Use sep equal to "\t" or " " for pretty formatting.

template textSerializer(string sep = "")
textSerializer
(
Appender
)
(
return Appender* appender
,
int serdeTarget = SerdeTarget.ion
)

Members

Functions

textSerializer
auto textSerializer(Appender* appender, int serdeTarget)

Examples

import mir.format: stringBuf;
import mir.bignum.integer;

auto buffer = stringBuf;
auto ser = textSerializer((()@trusted=>&buffer)());
auto state0 = ser.structBegin;

    ser.putKey("null");
    ser.putValue(null);

    ser.putKey("array");
    auto state1 = ser.listBegin();
        ser.elemBegin; ser.putValue(null);
        ser.elemBegin; ser.putValue(123);
        ser.elemBegin; ser.putValue(12300000.123);
        ser.elemBegin; ser.putValue("\t");
        ser.elemBegin; ser.putValue("\r");
        ser.elemBegin; ser.putValue("\n");
        ser.elemBegin; ser.putValue(BigInt!2(1234567890));
    ser.listEnd(state1);

ser.structEnd(state0);

assert(buffer.data == `{'null':null,array:[null,123,1.2300000123e+7,"\t","\r","\n",1234567890]}`);
    import std.array;
    import mir.bignum.integer;

    auto app = appender!string;
    auto ser = textSerializer!"    "(&app);
    auto state0 = ser.structBegin;

        ser.putKey("null");
        ser.putValue(null);

        ser.putKey("array");
        auto state1 = ser.listBegin();
            ser.elemBegin; ser.putValue(null);
            ser.elemBegin; ser.putValue(123);
            ser.elemBegin; ser.putValue(12300000.123);
            ser.elemBegin; ser.putValue("\t");
            ser.elemBegin; ser.putValue("\r");
            ser.elemBegin; ser.putValue("\n");
            ser.elemBegin; ser.putValue(BigInt!2("1234567890"));
        ser.listEnd(state1);

    ser.structEnd(state0);

    assert(app.data ==
`{
    'null': null,
    array: [
        null,
        123,
        1.2300000123e+7,
        "\t",
        "\r",
        "\n",
        1234567890
    ]
}`, app.data);

Meta