std.serialization: pre-voting review / discussion

ilya-stromberg ilya-stromberg-2009 at yandex.ru
Sat Aug 24 05:45:07 PDT 2013


On Friday, 23 August 2013 at 20:28:10 UTC, Jacob Carlborg wrote:
> On 2013-08-22 21:30, ilya-stromberg wrote:
>
>> What about more difficult cases?
>
> Actually, my previous answer was not entirely correct. By 
> default it will throw an exception. But you can implement the 
> above using custom serialization (here using Orange) :

Great job!
A little question. For example, I would like to load data from 
previos format and store current version in default 
std.serialization format. So, I don't want to implement "toData" 
at all? Is it possible? Or can I call the default serialization 
method? Something like this:

class Foo : Serializable
{
     long b;

     //I don't want to implement this
     void toData (Serializer serializer, Serializer.Data key)
     {
         serializer.serialize(this);
     }

     void fromData (Serializer serializer, Serializer.Data key)
     {
         b = serializer.deserialize!(int)("b");
     }
}

Also, please add this examlpe to the documentation, it could be 
useful for many users.

Note that we can split Serializable interface for 2 interfaces:

interface ToSerializable
{
     void toData(Serializer serializer, Serializer.Data key);
}

interface FromSerializable
{
     void fromData(Serializer serializer, Serializer.Data key);
}

interface Serializable : ToSerializable, FromSerializable
{
}

class Foo : FromSerializable
{
     long b;

     void fromData (Serializer serializer, Serializer.Data key)
     {
         b = serializer.deserialize!(int)("b");
     }

     //I must NOT to implement toData
}


More information about the Digitalmars-d mailing list