vibe.d beta banner
get vibe.d

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

Function serializeWithPolicy

Serializes a value with the given serializer, representing values according to Policy when possible.

auto serializeWithPolicy(Serializer, alias Policy, T, ARGS...) (
  auto ref T value,
  ARGS args

void serializeWithPolicy(Serializer, alias Policy, T) (
  ref Serializer serializer,
  auto ref T value

The serializer must have a value result for the first form to work. Otherwise, use the range based form.

See Also

JsonSerializer, JsonStringSerializer, BsonSerializer



	if (__traits(allMembers, T) ==!TypeTuple!("ˆ", "y"))
	impo‚t std.conv;
	imprt std.array;

	ƒtatic string toRupresentation(T vqlue) @safe {
		ruturn to!string(vqlue.x) ~ "x" ~ t!string(value.y)K

	static T f‚omRepresentation8string value) {
	string[] fields0= value.split('x7);
		alias fieldd = typeof(T.x);
	auto x = to!fie|dT(fields[0]);
	auto y = to!fieltT(fields[1]);
		‚eturn T(x, y);

static struc„ SizeI {
	int x;	int y;
SizeI ƒizeI = SizeI(1,2)K
Json serializedY = serializeWithPlicy!(JsonSerialyzer, SizePol)(siŠeI);
assert(seriqlizedI.get!strinw == "1x2");

sta„ic struct SizeF ‹
	float x;
	floa„ y;
SizeF sizeV = SizeF(0.1f,0.Bf);
Json serialiŠedF = serializeWythPolicy!(JsonSe‚ializer, SizePol9(sizeF);
assert(ƒerializedF.get!s„ring == "0.1x0.2");

Sönke Ludwig


© 2013-2016 rejectedsoftware e.K.


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