Serialization for D. Comments, please!

Denis Koroskin 2korden at gmail.com
Tue May 26 12:19:50 PDT 2009


On Tue, 26 May 2009 21:44:49 +0400, Bill Baxter <wbaxter at gmail.com> wrote:

> On Tue, May 26, 2009 at 2:35 AM, Denis Koroskin <2korden at gmail.com>  
> wrote:
>> On Tue, 26 May 2009 13:29:39 +0400, Qian Xu  
>> <quian.xu at stud.tu-ilmenau.de>
>> wrote:
>>
>>> BCS wrote:
>>>
>>>> I'm planning on taking a crack at a Serialization template library and
>>>> I'm
>>>> looking for feed back. My thinking so far is up on my blog here:
>>>>
>>>>
>>>
>>> http://arrayboundserror.blogspot.com/2009/05/serialization-for-d-part-1-of-n.html
>>>>
>>>> Please comment! (here or there, doesn't matter, I think I'll see both)
>>>
>>> A question:
>>> Should every object contain "mixin Serializable!()" in its declaration?
>>> It is easy to add this in own classes, but not easy to 3rd-party
>>> libraries.
>>> for instance: tango
>>>
>>>
>>> --Qian
>>>
>>
>> Good serialization library supports external serialization via template
>> specialization (or similar tricks) :)
>
> I'll also add that you should be able to properly
> serialize/deserialize a BaseClass pointer that actually points to a
> DerivedClass.
> This is pretty tricky to get working seamlessly when combined with the
> external serialization requirement.
> H3r3tic's xpose library has this working IIRC.
>
> --bb

Sure! How about the following test:

struct A
{
    mixin Serializable!();

    B[] b;
}

struct B
{
    mixin Serializable!();

    A a;
    int i;
}

B[] b = new B[1];
b[0].a.b = b;
b[0].i = 42;

A* a = &b[0].a;

data = serialize(a); // should serialize outer struct (B), too, because it is accessible through a

a = deserialize(data);
assert(a.b.length == 1);
assert(a.b[0].i == 42);

BTW, thanks for reminding about xpose. I gotta compare it, doost.serialize and mine own one against each other in terms of efficiency and size (for binary output) someday.


More information about the Digitalmars-d-announce mailing list