No conversion. More extensively covered by (de)serializer base tests in package_test.d
struct S { enum StructVersion = 1; int a = 42; double b = 2.0; } auto loader = new VersionDecorator; void[] buffer; S t; loader.store(t, buffer); Contiguous!(S) dst; loader.loadCopy!(S)(buffer, dst); test!("==")(dst.ptr.a, t.a); test!("==")(dst.ptr.b, t.b); dst = loader.load!(S)(buffer); test!("==")(dst.ptr.a, t.a); test!("==")(dst.ptr.b, t.b);
No conversion. Check non void[] API.
struct S { enum StructVersion = 1; int a = 42; } auto loader = new VersionDecorator; ubyte[] buffer; S t; loader.store(t, buffer); Contiguous!(S) dst; loader.loadCopy!(S)(buffer, dst); test!("==")(dst.ptr.a, t.a);
Error handling
auto loader = new VersionDecorator; void[] buffer = null; // must not accept non-versioned struct NoVersion { } static assert (!is(typeof(loader.load!(NoVersion)(buffer)))); // must detect if input size is too small struct Dummy { enum StructVersion = 1; } testThrown!(VersionHandlingException)(loader.load!(Dummy)(buffer)); Contiguous!(Dummy) dst; testThrown!(VersionHandlingException)( loader.loadCopy!(Dummy)(buffer, dst)); // must detect if conversion is not defined struct Dummy2 { enum StructVersion = 2; } loader.store(Dummy2.init, buffer); testThrown!(VersionHandlingException)(loader.load!(Dummy)(buffer)); loader.store(Dummy.init, buffer); testThrown!(VersionHandlingException)(loader.load!(Dummy2)(buffer));