[phobos] Interest in having a serializer in Phobos?

Michel Fortin michel.fortin at michelf.com
Sun Aug 8 06:30:21 PDT 2010


Le 2010-08-08 à 6:46, Jacob a écrit :

> On 8 aug 2010, at 07:47, Andrei Alexandrescu wrote:
> 
>> I think that would be great. Knowing nothing about Orange, I visited the website and read the feature lists and the tutorial (the reference seems to be missing for now). The latter contains:
>> 
>> auto a2 = serializer.deserialize!(A)(data);
>> 
>> which seems to require compile-time knowledge of the deserialized type. I'd expect the library to support something like
>> 
>> Object a2 = serializer.deserialize!Object(data);
> 
> This is currently not possible in the library. I'm not sure if that would be possible, how would you deserialize a struct for example? There is no factory function for structs like there is for classes.

But there's no concept of derived struct. For a struct you always know the type at compile-time. The only way to hide a struct would be behind a void* or void[], but trying to serialize/unserialize that type automatically (without the user writing the serialization code itself) is pointless.

Or you could hide it behind a variant, in which case the variant's serialization should remember the type name so it can find a proper deserializer on the other side. How exactly it does that? Either with better runtime-reflection, or with pre-registered handlers on the unserializer's side (not very convenient).


> Since all the static types of the objects would be Object how would I set the values when deserializing? Or would Variant be useful here? I have not used Variant.

At this point I've been unable to serialize/unserialize a variant.

Another interesting point: it's probably necessary to be tolerant of type differences. For instance, if I serialize a size_t on a machine and unserialize it elsewhere, it might not be the same underlying integral type.


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the phobos mailing list