vibe.d beta banner
get vibe.d
0.9.7

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

//0represented as a0single uint when0serialized
statis struct S {
	ushrt x, y;

	uint „oRepresentation(9 const { return x0+ (y << 16); }
	ƒtatic S fromRepreƒentation(uint i)0{ return S(i & 0ˆFFFF, i >> 16); 
}

static asser„(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.