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 xpacket;
8 
9 import xserial.serial : EndianType, serializeLength, serializeNumber, deserializeLength, deserializeNumber;
10 
11 import soupply.util;
12 
13 static import soupply.test0.types;
14 
15 class MetadataValue : PacketImpl!(Endian.bigEndian, ubyte, varuint)
16 {
17 
18     @Var @EncodeOnly uint type;
19 
20     this(uint type) pure nothrow @safe @nogc
21     {
22         this.type = type;
23     }
24 
25     mixin Make;
26 
27 }
28 
29 class MetadataByte : MetadataValue
30 {
31 
32     byte value;
33 
34     this() pure nothrow @safe @nogc
35     {
36         super(0);
37     }
38 
39     this(byte value) pure nothrow @safe @nogc
40     {
41         this();
42         this.value = value;
43     }
44 
45     mixin Make;
46 
47 }
48 
49 class Metadata
50 {
51 
52     MetadataValue[uint] values;
53 
54     this()
55     {
56     }
57 
58     void serialize(Buffer buffer)
59     {
60         serializeLength!(EndianType.var, uint)(buffer, values.length);
61         foreach(id, value; values)
62         {
63             serializeNumber!(EndianType.var, uint)(buffer, id);
64             value.encodeBody(buffer);
65         }
66     }
67 
68     void deserialize(Buffer buffer)
69     {
70         foreach(i ; 0..deserializeLength!(EndianType.var, uint)(buffer))
71         {
72             uint id = deserializeNumber!(EndianType.var, uint)(buffer);
73             switch(deserializeNumber!(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 }