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
High level serialization API
Authros Ilya Yaroshenko
- void
serializeValue
(S)(ref Sserializer
, typeof(null)); - null value serializationExamples:
import mir.ser.json: serializeJson; assert(serializeJson(null) == `null`, serializeJson(null));
- void
serializeValue
(S, V)(ref Sserializer
, auto const ref Vvalue
)
if (isNumeric!V && !is(V == enum)); - Number serializationExamples:
import mir.ser.json: serializeJson; assert(serializeJson(2.40f) == `2.4`); assert(serializeJson(float.nan) == `"nan"`); assert(serializeJson(float.infinity) == `"+inf"`); assert(serializeJson(-float.infinity) == `"-inf"`);
- void
serializeValue
(S, V)(ref Sserializer
, const Vvalue
)
if (is(V == bool) && !is(V == enum)); - Boolean serialization
- void
serializeValue
(S, V : char)(ref Sserializer
, const Vvalue
)
if (is(V == char) && !is(V == enum)); - Char serializationExamples:
import mir.ser.json: serializeJson; assert(serializeJson(true) == `true`);
- void
serializeValue
(S, V)(ref Sserializer
, in Vvalue
)
if (is(V == enum)); - Enum serializationExamples:
import mir.ser.json: serializeJson; import mir.ser.ion: serializeIon; import mir.ser.text: serializeText; import mir.deser.ion: deserializeIon; import mir.small_string; import mir.rc.array; enum Key { bar, @serdeKeys("FOO", "foo") foo } assert(serializeJson(Key.foo) == `"FOO"`); assert(serializeText(Key.foo) == `FOO`); assert(serializeIon(Key.foo).deserializeIon!Key == Key.foo); assert(serializeIon(Key.foo).deserializeIon!string == "FOO"); assert(serializeIon(Key.foo).deserializeIon!(SmallString!32) == "FOO"); auto rcstring = serializeIon(Key.foo).deserializeIon!(RCArray!char); assert(rcstring[] == "FOO");
- void
serializeValue
(S)(ref Sserializer
, scope const(char)[]value
); - String serializationExamples:
import mir.ser.json: serializeJson; assert(serializeJson("\t \" \\") == `"\t \" \\"`, serializeJson("\t \" \\"));
- void
serializeValue
(S, T)(ref Sserializer
, T[]value
)
if (!isSomeChar!T); - Array serialization
- void
serializeValue
(S, V)(ref Sserializer
, auto ref Vvalue
)
if (isIterable!V && (!hasProxy!V || hasLikeList!V) && !isDynamicArray!V && !hasFields!V && !isAssociativeArray!V && !isStdNullable!V); - Input range serializationExamples:input range serialization
import std.algorithm : filter; struct Foo { int i; } auto ar = [Foo(1), Foo(3), Foo(4), Foo(17)]; auto filtered1 = ar.filter!"a.i & 1"; auto filtered2 = ar.filter!"!(a.i & 1)"; import mir.ser.json: serializeJson; assert(serializeJson(filtered1) == `[{"i":1},{"i":3},{"i":17}]`); assert(serializeJson(filtered2) == `[{"i":4}]`);
Examples:import mir.ser.json: serializeJson; uint[2] ar = [1, 2]; assert(serializeJson(ar) == `[1,2]`); assert(serializeJson(ar[]) == `[1,2]`); assert(serializeJson(ar[0 .. 0]) == `[]`); assert(serializeJson((uint[]).init) == `[]`);
- void
serializeValue
(S, T)(ref Sserializer
, auto ref T[string]value
); - String-value associative array serializationExamples:
import mir.ser.json: serializeJson; import mir.ser.text: serializeText; uint[string] ar = ["a" : 1]; assert(serializeJson(ar) == `{"a":1}`); assert(serializeText(ar) == `{a:1}`); ar.remove("a"); assert(serializeJson(ar) == `{}`); assert(serializeJson((uint[string]).init) == `{}`);
- void
serializeValue
(S, V : const(T[K]), T, K)(ref Sserializer
, Vvalue
)
if (is(K == enum)); - Enumeration-value associative array serializationExamples:
import mir.ser.json: serializeJson; enum E { a, b } uint[E] ar = [E.a : 1]; assert(serializeJson(ar) == `{"a":1}`); ar.remove(E.a); assert(serializeJson(ar) == `{}`); assert(serializeJson((uint[string]).init) == `{}`);
- void
serializeValue
(S, V : const(T[K]), T, K)(ref Sserializer
, Vvalue
)
if (isIntegral!K && !is(K == enum)); - integral typed value associative array serializationExamples:
import mir.ser.json: serializeJson; uint[short] ar = [256 : 1]; assert(serializeJson(ar) == `{"256":1}`); ar.remove(256); assert(serializeJson(ar) == `{}`); assert(serializeJson((uint[string]).init) == `{}`); // assert(deserializeJson!(uint[short])(`{"256":1}`) == cast(uint[short]) [256 : 1]);
- void
serializeValueImpl
(S, V)(ref Sserializer
, auto ref Vvalue
)
if (isAggregateType!V && (!isIterable!V || hasFields!V || hasUDA!(V, serdeProxy) && !hasUDA!(V, serdeLikeList))); - Struct and class type serialization
- void
serializeValue
(S, V)(ref Sserializer
, auto ref Vvalue
)
if (isAggregateType!V && (!isIterable!V || hasFields!V || hasUDA!(V, serdeProxy) && !hasUDA!(V, serdeLikeList))); - Struct and class type serialization
- auto
beginList
(S, V)(ref Sserializer
, ref Vvalue
); - auto
beginSexp
(S, V)(ref Sserializer
, ref Vvalue
); - auto
beginStruct
(S, V)(ref Sserializer
, ref Vvalue
);
Copyright © 2016-2022 by Ilya Yaroshenko | Page generated by
Ddoc on Thu Mar 10 07:43:27 2022