lu.serialisation

Various functions related to serialising and deserialising structs into/from .ini-like files.

Members

Classes

DeserialisationException
class DeserialisationException

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

Enums

CannotContainComments (from lu.uda)
enum CannotContainComments via public import lu.uda : CannotContainComments, Quoted, Separator, Unserialisable;

UDA conveying that this member may contain characters that would otherwise indicate a comment, but isn't.

Quoted (from lu.uda)
enum Quoted via public import lu.uda : CannotContainComments, Quoted, Separator, Unserialisable;

UDA conveying that this member's value must be quoted when serialised.

Unserialisable (from lu.uda)
enum Unserialisable via public import lu.uda : CannotContainComments, Quoted, Separator, Unserialisable;

UDA conveying that a field cannot (or should not) be serialised.

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
void serialise(Sink sink, QualThing thing)

Serialises the fields of an object into an .ini file-like 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

Separator (from lu.uda)
struct Separator via public import lu.uda : CannotContainComments, Quoted, Separator, Unserialisable;

UDA conveying that the annotated array should have this token as separator when formatted to a string.

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.data.justifiedEntryValueText == fooJustified);

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

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

Meta