Implementing serialisation with minmal boilerplate and template overhead using core.reflect
Stefan Koch
uplink.coder at googlemail.com
Sun Aug 15 11:26:22 UTC 2021
On Sunday, 15 August 2021 at 11:18:57 UTC, Stefan Koch wrote:
> Good Day everyone,
>
> A friend asked me recently of core.reflect could be used for
> serialization.
> [ ... ]
>
> I would like to know what you think about this
There was a bug in the code I posted.
I should have run every path before calling it a day ;)
The code for dynamic array serialization
```d
ulong length = *cast(size_t*) ptr;
const void* values = *cast(const ubyte**)(ptr +
size_t.sizeof);
auto elemType = da.nextOf;
return serializeArray(length, ptr, elemType);
```
has to be
```d
ulong length = *cast(size_t*) ptr;
const ubyte* values = *cast(const ubyte**)(ptr +
size_t.sizeof);
auto elemType = da.nextOf;
return serializeArray(length, ptr, values);
```
and of course serializeArray has to write the length as well for
this to work as without the length information you cannot
de-serialize.
More information about the Digitalmars-d
mailing list