Enum member isCustomSerializable
Checks if a given type has a custom serialization representation.
enum isCustomSerializable(T)
= is(typeof(T .init .toRepresentation())) && is(typeof(T .fromRepresentation(T .init .toRepresentation())) == T);
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
.
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);