Serializer

This class represents a serializer. It's the main interface to the (de)serialization process and it's this class that actually performs most of the (de)serialization.

The serializer is the frontend in the serialization process, it's independent of the underlying archive type. It's responsible for collecting and tracking all values that should be (de)serialized. It's the serializer that adds keys and ID's to all values, keeps track of references to make sure that a given value (of reference type) is only (de)serialized once.

The serializer is also responsible for breaking up types that the underlying archive cannot handle, into primitive types that archive know how to (de)serialize.

Keys are used by the serializer to associate a name with a value. It's used to deserialize values independently of the order of the fields of a class or struct. They can also be used by the user to give a name to a value. Keys are unique within it's scope.

ID's are an unique identifier associated with each serialized value. The serializer uses the ID's to track values when (de)serializing reference types. An ID is unique across the whole serialized data.

class Serializer {}

Constructors

this
this(Archive archive)

Creates a new serializer using the given archive.

Members

Aliases

Data
alias Data = Archive.UntypedData

The type of the serialized data. This is an untyped format.

ErrorCallback
alias ErrorCallback = Archive.ErrorCallback

The type of error callback.

Id
alias Id = Archive.Id

The type of an ID.

Functions

archive
Archive archive()

Returns the receivers archive

callSerializer
void callSerializer(RegisterBase* baseWrapper, T value, string key)
Undocumented in source. Be warned that the author may not have intended to support it.
deserialize
T deserialize(Data data, string key)

Deserializes the given data to value of the given type.

deserialize
T deserialize(string key)

Deserializes the value with the given associated key.

deserialize
T deserialize()

Deserializes the value with the given associated key.

deserializeBase
void deserializeBase(T value)

Deserializes the base class(es) of an instance.

errorCallback
ErrorCallback errorCallback()

This callback will be called when an unexpected event occurs, i.e. an expected element is missing in the deserialization process.

errorCallback
ErrorCallback errorCallback(ErrorCallback errorCallback)

This callback will be called when an unexpected event occurs, i.e. an expected element is missing in the deserialization process.

overrideDeserializer
void overrideDeserializer(void delegate(ref Base, Serializer, Data) dg)
void overrideDeserializer(void delegate(ref T, Serializer, Data) dg)

Overrides a globally registered deserializer for the given type with a deserializer local to the receiver.

overrideDeserializer
void overrideDeserializer(void function(ref Base, Serializer, Data) func)
void overrideDeserializer(void function(ref T, Serializer, Data) func)

Overrides a globally registered deserializer for the given type with a deserializer local to the receiver.

overrideSerializer
void overrideSerializer(void delegate(Base, Serializer, Data) dg)
void overrideSerializer(void delegate(ref T, Serializer, Data) dg)
void overrideSerializer(void delegate(T, Serializer, Data) dg)

Overrides a globally registered serializer for the given type with a serializer local to the receiver.

overrideSerializer
void overrideSerializer(void function(Base, Serializer, Data) func)
void overrideSerializer(void function(ref T, Serializer, Data) func)
void overrideSerializer(void function(T, Serializer, Data) func)

Overrides a globally registered serializer for the given type with a serializer local to the receiver.

reset
void reset()

Resets the serializer.

serialize
Data serialize(T value, string key)

Serializes the given value.

serializeBase
void serializeBase(T value)

Serializes the base class(es) of an instance.

setDoNothingOnErrorCallback
void setDoNothingOnErrorCallback()

Set the error callback do nothing when an error occurs

setThrowOnErrorCallback
void setThrowOnErrorCallback()

Set the error callback to throw when an error occurs

Static functions

register
void register()

Registers the given type for (de)serialization.

registerDeserializer
void registerDeserializer(void delegate(ref Base, Serializer, Data) dg)
void registerDeserializer(void delegate(ref T, Serializer, Data) dg)

Registers a deserializer for the given type.

registerDeserializer
void registerDeserializer(void function(ref Base, Serializer, Data) func)
void registerDeserializer(void function(ref T, Serializer, Data) func)

Registers a deserializer for the given type.

registerSerializer
void registerSerializer(void delegate(Base, Serializer, Data) dg)
void registerSerializer(void delegate(ref T, Serializer, Data) dg)
void registerSerializer(void delegate(T, Serializer, Data) dg)

Registers a serializer for the given type.

registerSerializer
void registerSerializer(void function(Base, Serializer, Data) func)
void registerSerializer(void function(ref T, Serializer, Data) func)
void registerSerializer(void function(T, Serializer, Data) func)

Registers a serializer for the given type.

resetRegisteredTypes
void resetRegisteredTypes()

Resets all registered types registered via the "register" method

resetSerializers
void resetSerializers()

Resets all registered (de)serializers registered via the "registerSerializer" method. This method will not reset the overridden (de)serializers.

Structs

Pointer
struct Pointer(T)
Undocumented in source.

Examples

import std.stdio;
import orange.serialization._;
import orange.serialization.archives._;

class Foo
{
    int a;
}

void main ()
{
    auto archive = new XmlArchive!();
    auto serializer = new Serializer;

    auto foo = new Foo;
    foo.a = 3;

    serializer.serialize(foo);
    auto foo2 = serializer.deserialize!(Foo)(archive.untypedData);

    writeln(foo2.a); // prints "3"
    assert(foo.a == foo2.a);
}

Meta