1 /*
2  * This file has been automatically generated by Soupply and released under the MIT license.
3  * Generated from data/test0.xml
4  */
5 module soupply.test0.protocol.test;
6 
7 static import std.conv;
8 import std.typetuple : TypeTuple;
9 import packetmaker;
10 
11 import soupply.util;
12 import soupply.test0.metadata : Metadata;
13 import soupply.test0.packet : Test0Packet;
14 
15 static import soupply.test0.types;
16 
17 alias Packets = TypeTuple!(TestInt, TestFloat, TestArray);
18 
19 class TestInt : Test0Packet
20 {
21 
22     enum ubyte ID = 0;
23 
24     enum bool CLIENTBOUND = false;
25     enum bool SERVERBOUND = false;
26 
27     enum string[] __fields = ["a", "b", "c", "d", "e"];
28 
29     byte a;
30     ushort b;
31     @LittleEndian long c;
32     @Var short d;
33     @Var uint e;
34 
35     this() pure nothrow @safe @nogc {}
36 
37     this(byte a, ushort b=ushort.init, long c=long.init, short d=short.init, uint e=uint.init) pure nothrow @safe @nogc
38     {
39         this.a = a;
40         this.b = b;
41         this.c = c;
42         this.d = d;
43         this.e = e;
44     }
45 
46     mixin Make;
47 
48     public static typeof(this) fromBuffer(ubyte[] buffer)
49     {
50         TestInt ret = new TestInt();
51         ret.autoDecode(buffer);
52         return ret;
53     }
54 
55     override string toString()
56     {
57         return "TestInt(a: " ~ std.conv.to!string(this.a) ~ ", b: " ~ std.conv.to!string(this.b) ~ ", c: " ~ std.conv.to!string(this.c) ~ ", d: " ~ std.conv.to!string(this.d) ~ ", e: " ~ std.conv.to!string(this.e) ~ ")";
58     }
59 
60     unittest
61     {
62 
63         import std.conv : to;
64 
65         TestInt packet = new TestInt();
66 
67         packet.d = 10;
68         packet.e = 500;
69         packet.b = 300;
70         packet.c = 1;
71         packet.a = -10;
72         auto result = packet.autoEncode();
73         assert(result == [0, 246, 1, 44, 1, 0, 0, 0, 0, 0, 0, 0, 20, 244, 3], `test0.test.test-int expected [0, 246, 1, 44, 1, 0, 0, 0, 0, 0, 0, 0, 20, 244, 3] but got ` ~ result.to!string);
74 
75         packet.autoDecode([0, 246, 1, 44, 1, 0, 0, 0, 0, 0, 0, 0, 20, 244, 3]);
76         assert(packet.d == 10, `test0.test.test-int.d expected 10 but got ` ~ packet.d.to!string);
77         assert(packet.e == 500, `test0.test.test-int.e expected 500 but got ` ~ packet.e.to!string);
78         assert(packet.b == 300, `test0.test.test-int.b expected 300 but got ` ~ packet.b.to!string);
79         assert(packet.c == 1, `test0.test.test-int.c expected 1 but got ` ~ packet.c.to!string);
80         assert(packet.a == -10, `test0.test.test-int.a expected -10 but got ` ~ packet.a.to!string);
81 
82     }
83 
84 }
85 
86 class TestFloat : Test0Packet
87 {
88 
89     enum ubyte ID = 1;
90 
91     enum bool CLIENTBOUND = false;
92     enum bool SERVERBOUND = false;
93 
94     enum string[] __fields = ["a", "b", "c"];
95 
96     float a;
97     double b;
98     @LittleEndian float c;
99 
100     this() pure nothrow @safe @nogc {}
101 
102     this(float a, double b=double.init, float c=float.init) pure nothrow @safe @nogc
103     {
104         this.a = a;
105         this.b = b;
106         this.c = c;
107     }
108 
109     mixin Make;
110 
111     public static typeof(this) fromBuffer(ubyte[] buffer)
112     {
113         TestFloat ret = new TestFloat();
114         ret.autoDecode(buffer);
115         return ret;
116     }
117 
118     override string toString()
119     {
120         return "TestFloat(a: " ~ std.conv.to!string(this.a) ~ ", b: " ~ std.conv.to!string(this.b) ~ ", c: " ~ std.conv.to!string(this.c) ~ ")";
121     }
122 
123     unittest
124     {
125 
126         import std.conv : to;
127 
128         TestFloat packet = new TestFloat();
129 
130         packet.b = 312;
131         packet.c = -44;
132         packet.a = 1;
133         auto result = packet.autoEncode();
134         assert(result == [1, 63, 128, 0, 0, 64, 115, 128, 0, 0, 0, 0, 0, 0, 0, 48, 194], `test0.test.test-float expected [1, 63, 128, 0, 0, 64, 115, 128, 0, 0, 0, 0, 0, 0, 0, 48, 194] but got ` ~ result.to!string);
135 
136         packet.autoDecode([1, 63, 128, 0, 0, 64, 115, 128, 0, 0, 0, 0, 0, 0, 0, 48, 194]);
137         assert(packet.b == 312, `test0.test.test-float.b expected 312 but got ` ~ packet.b.to!string);
138         assert(packet.c == -44, `test0.test.test-float.c expected -44 but got ` ~ packet.c.to!string);
139         assert(packet.a == 1, `test0.test.test-float.a expected 1 but got ` ~ packet.a.to!string);
140 
141     }
142 
143 }
144 
145 class TestArray : Test0Packet
146 {
147 
148     enum ubyte ID = 2;
149 
150     enum bool CLIENTBOUND = false;
151     enum bool SERVERBOUND = false;
152 
153     enum string[] __fields = ["a", "b", "c", "d"];
154 
155     ubyte[] a;
156     string b;
157     @Length!int short[] c;
158     @Var uint[] d;
159 
160     this() pure nothrow @safe @nogc {}
161 
162     this(ubyte[] a, string b=string.init, short[] c=(short[]).init, uint[] d=(uint[]).init) pure nothrow @safe @nogc
163     {
164         this.a = a;
165         this.b = b;
166         this.c = c;
167         this.d = d;
168     }
169 
170     mixin Make;
171 
172     public static typeof(this) fromBuffer(ubyte[] buffer)
173     {
174         TestArray ret = new TestArray();
175         ret.autoDecode(buffer);
176         return ret;
177     }
178 
179     override string toString()
180     {
181         return "TestArray(a: " ~ std.conv.to!string(this.a) ~ ", b: " ~ std.conv.to!string(this.b) ~ ", c: " ~ std.conv.to!string(this.c) ~ ", d: " ~ std.conv.to!string(this.d) ~ ")";
182     }
183 
184     unittest
185     {
186 
187         import std.conv : to;
188 
189         TestArray packet = new TestArray();
190 
191         packet.d = [0, 400];
192         packet.b = "test";
193         packet.c = [-1, 0, 1];
194         packet.a = [3, 2];
195         auto result = packet.autoEncode();
196         assert(result == [2, 2, 3, 2, 4, 116, 101, 115, 116, 0, 3, 255, 255, 0, 0, 0, 1, 2, 0, 144, 3], `test0.test.test-array expected [2, 2, 3, 2, 4, 116, 101, 115, 116, 0, 3, 255, 255, 0, 0, 0, 1, 2, 0, 144, 3] but got ` ~ result.to!string);
197 
198         packet.autoDecode([2, 2, 3, 2, 4, 116, 101, 115, 116, 0, 3, 255, 255, 0, 0, 0, 1, 2, 0, 144, 3]);
199         assert(packet.d == [0, 400], `test0.test.test-array.d expected [0,400] but got ` ~ packet.d.to!string);
200         assert(packet.b == "test", `test0.test.test-array.b expected "test" but got ` ~ packet.b.to!string);
201         assert(packet.c == [-1, 0, 1], `test0.test.test-array.c expected [-1,0,1] but got ` ~ packet.c.to!string);
202         assert(packet.a == [3, 2], `test0.test.test-array.a expected [3,2] but got ` ~ packet.a.to!string);
203 
204     }
205 
206 }