Enum member isCustomSerializable
Checks if a given type has a custom serialization representation.
A class or struct type is custom serializable if it defines a pair of
toRepresentation
/
fromRepresentation
methods. Any class or
struct type that has this trait will be serialized by using the return
value of it's toRepresentation
method instead of the original value.
This trait has precedence over isISOExtStringSerializable
and
isStringSerializable
.
Declaration
enum isCustomSerializable(T) = is(typeof(T .init .toRepresentation())) && is(typeof(T .fromRepresentation(T .init .toRepresentation())) == T);
Example
// represented as a single uint when serialized
static struct S {
ushort x, y;
uint toRepresentation() const { return x + (y << 16); }
static S fromRepresentation(uint i) { return S(i & 0xFFFF, i >> 16); }
}
static assert(isCustomSerializable!S);
Authors
Sönke Ludwig
Copyright
© 2013-2014 rejectedsoftware e.K.
License
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.