lu.serialisation

Various functions related to serialising and deserialising structs into/from configuration file-y files.

Members

Classes

DeserialisationException
class DeserialisationException

Exception, to be thrown when the specified serialised text could not be parsed, for whatever reason.

Functions

deserialise
void deserialise(Range range, string[][string] missingEntries, string[][string] invalidEntries, Things things)

Takes an input range containing serialised entry-value text and applies the contents therein to one or more passed struct/class objects.

justifiedEntryValueText
string justifiedEntryValueText(string origLines)

Takes an unformatted string of serialised entry-value text and justifies it into two neat columns.

serialise
void serialise(Sink sink, Things things)

Convenience function to call serialise on several objects.

serialise
auto serialise(Sink sink, QualThing thing)

Serialises the fields of an object into a configuration file-y format.

serialiseArrayImpl
string serialiseArrayImpl(T array, SerialisationUDAs udas)

Serialises a non-string array into a single row. To be used when serialising an aggregate with serialise.

splitEntryValue
auto splitEntryValue(string line)

Splits a line into an entry and a value component.

Structs

SerialisationUDAs
struct SerialisationUDAs

Summary of UDAs that an array to be serialised is annotated with.

Examples

struct FooSettings
{
    string fooasdf;
    string bar;
    string bazzzzzzz;
    @Quoted flerrp;
    double pi;
}

FooSettings f;

f.fooasdf = "foo";
f.bar = "bar";
f.bazzzzzzz = "baz";
f.flerrp = "hirr steff  ";
f.pi = 3.14159;

enum fooSerialised =
`[Foo]
fooasdf foo
bar bar
bazzzzzzz baz
flerrp "hirr steff  "
pi 3.14159`;

enum fooJustified =
`[Foo]
fooasdf                 foo
bar                     bar
bazzzzzzz               baz
flerrp                  "hirr steff  "
pi                      3.14159`;

Appender!(char[]) sink;

sink.serialise(f);
assert(sink[].justifiedEntryValueText == fooJustified);

FooSettings mirror;
deserialise(fooSerialised, mirror);
assert(mirror == f);

FooSettings mirror2;
deserialise(fooJustified, mirror2);
assert(mirror2 == mirror);

Meta