Request for pre-review: std.serialization/orange

Robert Jacques sandford at jhu.edu
Fri Sep 30 20:00:12 PDT 2011


On Fri, 30 Sep 2011 10:41:48 -0400, Jacob Carlborg <doob at me.com> wrote:
> On 2011-09-30 15:03, Robert Jacques wrote:
>> On Thu, 29 Sep 2011 14:58:30 -0400, Jacob Carlborg <doob at me.com> wrote:

[snip]

>> The method should also be static: If I'm registering a custom
>> serialization method, I don't want to duplicate that mapping everywhere
>> a serializer is instanced. I don't even want to duplicate it for every
>> type of serializer. I think there needs to be some granularity for this:
>> i.e. instance -> type -> global.
>
> "register" is static, "registerSerializer" is not because I'm not
> entirely sure how I want the API to behave.
>
> What if I want to serialize a class in two different places. In one
> place I want to serialize it by default and in the other I want to do
> custom serialization?

I agree, which is why I suggested lookup should have some granuality. i.e. that there is both a global store of serialization methods and a per instance store of serialization methods. Lookup would first look in the local store before defaulting to the global store. But this should be a separate pair of functions.

> "I don't even want to duplicate it for every type of serializer". I'm
> not sure I quite understand, there's only one type of serializer.

I'm sorry, I was thinking about archive types (i.e. JSON vs XML) and somehow thinking that the Serializers would be different for each. (I was thinking that the serializer was templated on the archive for some reason.)

>> Also, repeat the above for registerDeserializer.
>>
>>
>> Re: deserialize some of the example don't look like they're correct.
>
> They look correct to me. Note that two of the three "deserialize"
> methods should only be called when performing custom deserialization of
> a class/strut. This method will then, most likely, be called from within
> the class to manually deserialize the fields.
>

Both

T deserialize  (T)();
T deserialize  (T)(string key);

have the following example:

  class Foo
  {
  	int a;

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


More information about the Digitalmars-d mailing list