std.serialization

Orvid King blah38621 at gmail.com
Sun Feb 16 09:52:47 PST 2014


> What features does it support? How does it handle:
>
> * Arrays
> * Slices
> * Pointers
> * Reference types
> * Support for events
> * Custom serialization
> * Serialization of third party types

Slices are handled as arrays, because of the fact that they need 
to be handled in such a way that many different types of 
serialization formats can support them, and be inter-operable 
with implementations in languages other than D.

Pointers are not supported, because in my opinion, they should 
_NEVER_ be serialized.

Reference types are serialized as they are encountered, I haven't 
handled the circular reference case yet.

Events are not supported due to the fact it would require 
complete knowledge of the source and target environments of the 
serialization.

Custom serialization is supported by either supporting 
to!YourType(string) or YourType.parse(string) / 
to!string(valueOfYourType) or valueOfYourType.toString(), and are 
handled transparently by the base serialization handler, the 
actual serialization format sees them simply as strings. Each 
serialization format however does have the ability to select any 
type it wants to support being serialized.

And third party types are only supported if they have the 
requisite UDA, or support custom serialization.

> Why require a UDA?
The UDA is required for the exact same reason it's required in 
the .net framework, because it makes sure that the type you are 
trying to serialize is serialization aware, meaning that it's not 
serializing cache fields, and also makes sense to actually be 
serializing the type.


More information about the Digitalmars-d-announce mailing list