Deserializes and returns a serialized value.
Serializes a value with the given serializer.
Attribute for representing a struct/class as an array instead of an object.
Attribute marking a field as optional during deserialization.
Checks if a given type has a string serialization representation.
The following rules are applied in order when serializing or deserializing a certain type:
Note that no aliasing detection is performed, so that pointers, class references and arrays referencing the same memory will be serialized as multiple copies. When in turn deserializing the data, they will also end up as separate copies in memory.
By default, the field name of the serialized D type (for struct and class aggregates) is represented as-is in the serialized result. To circumvent name clashes with D's keywords, a single trailing underscore of any field name is stipped, so that a field name of version_ results in just "version" as the serialized value. Names can also be freely customized using the @name annotation.
Associative array keys are always represented using their direct string representation.
Serializers are implemented in terms of a struct with template methods that get called by the serialization framework:
struct ExampleSerializer { enum isSupportedValueType(T) = is(T == string) || is(T == typeof(null)); // serialization auto getSerializedResult(); void beginWriteDocument(TypeTraits)(); void endWriteDocument(TypeTraits)(); void beginWriteDictionary(TypeTraits)(size_t length); [OR] void beginWriteDictionary(TypeTraits)(); void endWriteDictionary(TypeTraits)(); void beginWriteDictionaryEntry(ElementTypeTraits)(string name); void endWriteDictionaryEntry(ElementTypeTraits)(string name); void beginWriteArray(TypeTraits)(size_t length); void endWriteArray(TypeTraits)(); void beginWriteArrayEntry(ElementTypeTraits)(size_t index); void endWriteArrayEntry(ElementTypeTraits)(size_t index); void writeValue(TypeTraits, T)(T value); // deserialization void readDictionary(TypeTraits)(scope void delegate(string) entry_callback); void beginReadDictionaryEntry(ElementTypeTraits)(string); void endReadDictionaryEntry(ElementTypeTraits)(string); void readArray(TypeTraits)(scope void delegate(size_t) size_callback, scope void delegate() entry_callback); void beginReadArrayEntry(ElementTypeTraits)(size_t index); void endReadArrayEntry(ElementTypeTraits)(size_t index); T readValue(TypeTraits, T)(); bool tryReadNull(TypeTraits)(); }
The TypeTraits type passed to the individual methods has the following members:
ElementTypeTraits have the following additional members:
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
© 2013-2016 rejectedsoftware e.K.
Generic serialization framework.
This module provides general means for implementing (de-)serialization with a standardized behavior.