The OpenD Programming Language

SerializerWrapper

Serializer interface wrapper for common serializers.

final
class SerializerWrapper : ISerializer (
S
) {}

Constructors

this
this(S serializer)

Inherited Members

From ISerializer

putStringPart
void putStringPart(const(char)[] value)

Puts string part. The implementation allows to split string unicode points.

stringEnd
void stringEnd(size_t state)
structBegin
size_t structBegin(size_t length)
structEnd
void structEnd(size_t state)
listBegin
size_t listBegin(size_t length)
listEnd
void listEnd(size_t state)
sexpBegin
size_t sexpBegin(size_t length)
sexpEnd
void sexpEnd(size_t state)
putSymbol
void putSymbol(char[] symbol)
putAnnotation
void putAnnotation(const(char)[] annotation)
annotationsEnd
size_t annotationsEnd(size_t state)
annotationWrapperBegin
size_t annotationWrapperBegin()
annotationWrapperEnd
void annotationWrapperEnd(size_t annotationsState, size_t state)
nextTopLevelValue
void nextTopLevelValue()
putKey
void putKey(char[] key)
putValue
void putValue(ubyte value)
putValue
void putValue(ushort value)
putValue
void putValue(uint value)
putValue
void putValue(byte value)
putValue
void putValue(short value)
putValue
void putValue(int value)
putValue
void putValue(long value)
putValue
void putValue(ulong value)
putValue
void putValue(float value)
putValue
void putValue(double value)
putValue
void putValue(real value)
putValue
void putValue(BigInt!128 value)
putValue
void putValue(Decimal!128 value)
putValue
void putValue(typeof(null) )
putNull
void putNull(IonTypeCode code)
putValue
void putValue(bool b)
putValue
void putValue(char[] value)
putValue
void putValue(Clob value)
putValue
void putValue(Blob value)
putValue
void putValue(Timestamp value)
elemBegin
void elemBegin()
sexpElemBegin
void sexpElemBegin()
serdeTarget
int serdeTarget()

Examples

static struct Wrapper(T)
{
    T value;

    void serialize(ISerializer serializer) const @safe
    {
        import mir.ser: serializeValue;
        serializeValue(serializer, value);
    }
}

static auto wrap(T)(T value)
{
    return Wrapper!T(value);
}

import mir.ion.conv;
import mir.ser.ion;
import mir.ser.json;
import mir.ser.text;
import mir.ion.stream;
import std.datetime.date;

assert(wrap(Date(1234, 5, 6)).serializeJson == `"1234-05-06"`);
assert(wrap(Date(1234, 5, 6)).serializeText == `1234-05-06`);
assert(wrap(Date(1234, 5, 6)).serializeIon.ion2text == `1234-05-06`);
immutable(ushort)[] imdata = [10, 20, 30];
assert(wrap(imdata).serializeIon.ion2text == `[10,20,30]`);

const ubyte[] data = [0xe0, 0x01, 0x00, 0xea, 0xe9, 0x81, 0x83, 0xd6, 0x87, 0xb4, 0x81, 0x61, 0x81, 0x62, 0xd6, 0x8a, 0x21, 0x01, 0x8b, 0x21, 0x02];
auto json = wrap(data.IonValueStream).serializeJson;
assert(json == `{"a":1,"b":2}`);

Meta