1 /* 2 * This file has been automatically generated by Soupply and released under the MIT license. 3 * Generated from test0 4 */ 5 module soupply.test0.metadata; 6 7 import packetmaker; 8 import packetmaker.maker : EndianType, writeLength, writeImpl, readLength, readImpl; 9 10 import soupply.util; 11 12 static import soupply.test0.types; 13 14 class MetadataValue : PacketImpl!(Endian.bigEndian, ubyte, varuint) 15 { 16 17 @Var @EncodeOnly uint type; 18 19 this(uint type) pure nothrow @safe @nogc 20 { 21 this.type = type; 22 } 23 24 mixin Make; 25 26 } 27 28 class MetadataByte : MetadataValue 29 { 30 31 byte value; 32 33 this() pure nothrow @safe @nogc 34 { 35 super(0); 36 } 37 38 this(byte value) pure nothrow @safe @nogc 39 { 40 this(); 41 this.value = value; 42 } 43 44 mixin Make; 45 46 } 47 48 struct Metadata 49 { 50 51 MetadataValue[uint] values; 52 53 void encodeBody(Buffer buffer) 54 { 55 writeLength!(EndianType.var, uint)(buffer, values.length); 56 foreach(id, value; values) 57 { 58 writeImpl!(EndianType.var, uint)(buffer, id); 59 value.encodeBody(buffer); 60 } 61 } 62 63 void decodeBody(Buffer buffer) 64 { 65 foreach(i ; 0..readLength!(EndianType.var, uint)(buffer)) 66 { 67 uint id = readImpl!(EndianType.var, uint)(buffer); 68 switch(readImpl!(EndianType.var, uint)(buffer)) 69 { 70 case 0: 71 auto value = new MetadataByte(); 72 value.decodeBody(buffer); 73 this.values[id] = value; 74 break; 75 default: throw new Exception("Unknown metadata type"); 76 } 77 } 78 } 79 80 }