vibe.d beta banner
get vibe.d
0.10.0

Asynchronous I/O that doesn’t get in your way, written in D

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);
Authors

Sönke Ludwig

Copyright

© 2013-2016 rejectedsoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.