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 enum MetadataType : uint 15 { 16 BYTE = 0, 17 } 18 19 class MetadataValue : PacketImpl!(Endian.bigEndian, ubyte, varuint) 20 { 21 22 @Var @EncodeOnly uint type; 23 24 this(uint type) pure nothrow @safe @nogc 25 { 26 this.type = type; 27 } 28 29 mixin Make; 30 31 } 32 33 class MetadataByte : MetadataValue 34 { 35 36 byte value; 37 38 this() pure nothrow @safe @nogc 39 { 40 super(0); 41 } 42 43 this(byte value) pure nothrow @safe @nogc 44 { 45 this(); 46 this.value = value; 47 } 48 49 mixin Make; 50 51 } 52 53 struct Metadata 54 { 55 56 MetadataValue[uint] values; 57 58 void encodeBody(Buffer buffer) 59 { 60 writeLength!(EndianType.var, uint)(buffer, values.length); 61 foreach(id, value; values) 62 { 63 writeImpl!(EndianType.var, uint)(buffer, id); 64 value.encodeBody(buffer); 65 } 66 } 67 68 void decodeBody(Buffer buffer) 69 { 70 foreach(i ; 0..readLength!(EndianType.var, uint)(buffer)) 71 { 72 uint id = readImpl!(EndianType.var, uint)(buffer); 73 switch(readImpl!(EndianType.var, uint)(buffer)) 74 { 75 case 0: 76 auto value = new MetadataByte(); 77 value.decodeBody(buffer); 78 this.values[id] = value; 79 break; 80 default: throw new Exception("Unknown metadata type"); 81 } 82 } 83 } 84 85 }