MapSerializer

Offers functionality to load/dump the content of Maps (optionally of anything actually, using the delegate version of the dump/load functions).

Features include backwards compability with auto-conversion to the requested struct version. It makes use of the same functions that the StructLoader/StructDumper use for the conversion.

This means that structs used with this function should have the const member StructVersion as well as an alias to the old version (if one exists) called "StructPrevious" (this is identical to the requirements for vesioned struct in the StructDumper/Loader).

Additionally, a validation using the struct hash is done too, to exclude potential human errors while setting up the version info.

If you have a map saved in the old version (2) and at the same time updated the struct definition of that map, you can still take advantage of the auto-conversion functionality if you simply define the old struct version as version 0 and your current one as version 1. The loader is smart enough to figure out the old version by hash and converts it to the newer one.

Usage Example:

struct MyValue0
{
    const StructVersion = 0;
    int my_value;
}

auto serializer = new MapSerializer;
auto myMap = new HashMap!(MyValue0)(10);

// Assume code to fill map with values here
//...
//

serializer.dump(myMap, "version0.map");

// Later...

serilizer.load(myMap, "version0.map");


// Now, if you have changed the struct, create a new version of it

struct MyValue1
{
    const StructVersion = 1;
    int my_value;

    int my_new_value;

    void convert_my_new_value ( ref MyValue0 old )
    {
        this.my_new_value = old.my_value * 2;
    }
}

// This is our map with the new version
auto myNewMap = new HashMap!(MyValue1)(10);

// Load old version
serializer.load(myNewMap, "version0.map");

// .. use map as desired.

// You can do the same thing with the key in case it is a struct.

Constructors

this
this(size_t buffer_size)

Constructor

Members

Classes

UnexpectedEndException
class UnexpectedEndException

Exception thrown when the file that was loaded is incomplete. Will soon be unused

Functions

dump
void dump(Map!(V, K) map, cstring file_path)

Writes a map to a file.

dumpConduit
void dumpConduit(Map!(V, K) map, IConduit io_device)

Writes a map to an IO device.

dumpDg
void dumpDg(cstring file_path, AdderDg!(K, V) adder)

Writes a map to a file.

dumpDgConduit
void dumpDgConduit(IConduit io_device, AdderDg!(K, V) adder)

Writes a map to an IO device.

load
void load(Map!(V, K) map, cstring file_path)

loads dumped map content from the file system

loadConduit
void loadConduit(Map!(V, K) map, IConduit io_device)

loads dumped map content from the file system

loadDg
void loadDg(cstring file_path, PutterDg!(K, V) putter)

Loads dumped map content from the file system

loadDgConduit
void loadDgConduit(IConduit io_device, PutterDg!(K, V) putter)

Loads dumped map content from the file system

Structs

BufferPair
struct BufferPair

Pair of buffers used for conversion

Templates

AddPtr
template AddPtr(T...)

Takes a type tuple and transforms it into the same type tuple but with the types being pointers to the original types.

AddStructPrevious
template AddStructPrevious(ubyte index, T...)

Helper template for version handling. Takes a tuple of types and changes the type and position index to what ever it has as .StructPrevious member.

AdderDg
template AdderDg(K, V)

Delegate used to add new values from a map

PutterDg
template PutterDg(K, V)

Delegate used to put values in a map

StructHash
template StructHash(S)

Evaluates to the fnv1 hash of the types that make up the struct. If S is no struct, mangled name of the type is used.

Meta