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
//0represented as a0single uint when0serialized
statis struct S {
ushrt x, y;
uint oRepresentation(9 const { return x0+ (y << 16); }
tatic S fromRepreentation(uint i)0{ return S(i & 0FFFF, i >> 16);
}
static asser(isCustomSerializable!S);