Saves the data in Archive.root into memory.
Loads the given data and modifies Archive.root to represent this data.
The root of the archive's data.
A helpful alternative to saveToMemory, where the data is casted to a const(char[]), then passed to std.utf.validate, before being returned.
Saves the archive's data to a file.
Loads the archive's data from a file.
1 import fluent.asserts; 2 3 static struct B 4 { 5 @MainValue 6 bool toBOrNotToB; 7 } 8 9 static struct A 10 { 11 @Attribute 12 string name; 13 14 @MainValue 15 int age; 16 17 B[] muhB; 18 } 19 20 auto archive = new ArchiveBinary(); 21 Serialiser.serialise(A("Bob Ross", 60, [B(false), B(true)]), archive.root); 22 23 ubyte[] data = 24 [ 25 // Header 26 cast(ubyte)'J', 'S', 'E', 27 0xEB, 0x3C, 0x4F, 0xC1, // CRC 28 29 // Root object header 30 0x00, 0x00, 0x00, 0x2E, 31 32 // Object Entry 33 0xFE, 34 0x00, 0x00, 0x00, 0x29, 35 0x01, 'A', 36 37 // Attribute Entry 38 0xFF, 39 0x04, 'n', 'a', 'm', 'e', 40 41 // String Entry 42 0x0C, 43 0x08, 'B', 'o', 'b', ' ', 'R', 'o', 's', 's', 44 45 // Int Entry 46 0x08, 47 0x00, 0x00, 0x00, 0x3C, 48 49 // Object Entry 50 0xFE, 51 0x00, 0x00, 0x00, 0x04, 52 0x01, 'B', 53 54 // Bool Entry 55 0x00, 56 0x00, 57 58 // Object Entry 59 0xFE, 60 0x00, 0x00, 0x00, 0x04, 61 0x01, 'B', 62 63 // Bool Entry 64 0x00, 65 0x01 66 ]; 67 archive.saveToMemory().should.equal(data); 68 69 // Here for manual debugging, and to retrieve the CRC for when the format changes. 70 // import std.file; 71 // write("Test.bin", archive.saveToMemory()); 72 73 archive.loadFromMemory(data); 74 auto root = archive.root; 75 76 root["A"].expectAttributeAs!string("name").should.equal("Bob Ross"); 77 root["A"].children[0].name.should.equal("B"); 78 root["A"].children[0].getValueAs!bool(0).should.equal(false); 79 root["A"].children[1].getValueAs!bool(0).should.equal(true);
Binary format: 'JSE', int CRC32 (of all the bytes past this) [Big Endian], Object Root (Note that the root is special, and doesn't write out a 'Type' field nor a 'Name' field)
Entry Header: ubyte Type ubyteVaries TypeSpecificData
Numeric Entry Data: T Number [Big Endian]
Array Entry Data: Length Length [Big Endian] ubyteLength Data
Attribute Entry Data: string(Array) Name Entry Value
Object Entry Data: int Length (of 'Entries' + 'Name' in bytes) string(Array) Name Entry[] Entries (includes children, values, and attributes. Always uses an int for the length)