1 /*
2  * This file was automatically generated by sel-utils and
3  * released under the MIT License.
4  * 
5  * License: https://github.com/sel-project/sel-utils/blob/master/LICENSE
6  * Repository: https://github.com/sel-project/sel-utils
7  * Generated from https://github.com/sel-project/sel-utils/blob/master/xml/protocol/raknet8.xml
8  */
9 module sul.protocol.raknet8.encapsulated;
10 
11 import std.bitmanip : write, peek;
12 static import std.conv;
13 import std.system : Endian;
14 import std.typetuple : TypeTuple;
15 import std.typecons : Tuple;
16 import std.uuid : UUID;
17 
18 import sul.utils.buffer;
19 import sul.utils.var;
20 
21 static import sul.protocol.raknet8.types;
22 
23 static if(__traits(compiles, { import sul.metadata.raknet8; })) import sul.metadata.raknet8;
24 
25 alias Packets = TypeTuple!(ClientConnect, ServerHandshake, ClientHandshake, ClientCancelConnection, Ping, Pong, Mcpe);
26 
27 class ClientConnect : Buffer {
28 
29 	public enum ubyte ID = 9;
30 
31 	public enum bool CLIENTBOUND = false;
32 	public enum bool SERVERBOUND = true;
33 
34 	public enum string[] FIELDS = ["clientId", "pingId"];
35 
36 	public long clientId;
37 	public long pingId;
38 
39 	public pure nothrow @safe @nogc this() {}
40 
41 	public pure nothrow @safe @nogc this(long clientId, long pingId=long.init) {
42 		this.clientId = clientId;
43 		this.pingId = pingId;
44 	}
45 
46 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
47 		_buffer.length = 0;
48 		static if(writeId){ writeBigEndianUbyte(ID); }
49 		writeBigEndianLong(clientId);
50 		writeBigEndianLong(pingId);
51 		return _buffer;
52 	}
53 
54 	public pure nothrow @safe void decode(bool readId=true)() {
55 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
56 		clientId=readBigEndianLong();
57 		pingId=readBigEndianLong();
58 	}
59 
60 	public static pure nothrow @safe ClientConnect fromBuffer(bool readId=true)(ubyte[] buffer) {
61 		ClientConnect ret = new ClientConnect();
62 		ret._buffer = buffer;
63 		ret.decode!readId();
64 		return ret;
65 	}
66 
67 	public override string toString() {
68 		return "ClientConnect(clientId: " ~ std.conv.to!string(this.clientId) ~ ", pingId: " ~ std.conv.to!string(this.pingId) ~ ")";
69 	}
70 
71 }
72 
73 class ServerHandshake : Buffer {
74 
75 	public enum ubyte ID = 16;
76 
77 	public enum bool CLIENTBOUND = true;
78 	public enum bool SERVERBOUND = false;
79 
80 	public enum string[] FIELDS = ["clientAddress", "mtuLength", "systemAddresses", "pingId", "serverId"];
81 
82 	public sul.protocol.raknet8.types.Address clientAddress;
83 	public ushort mtuLength;
84 	public sul.protocol.raknet8.types.Address[10] systemAddresses;
85 	public long pingId;
86 	public long serverId;
87 
88 	public pure nothrow @safe @nogc this() {}
89 
90 	public pure nothrow @safe @nogc this(sul.protocol.raknet8.types.Address clientAddress, ushort mtuLength=ushort.init, sul.protocol.raknet8.types.Address[10] systemAddresses=(sul.protocol.raknet8.types.Address[10]).init, long pingId=long.init, long serverId=long.init) {
91 		this.clientAddress = clientAddress;
92 		this.mtuLength = mtuLength;
93 		this.systemAddresses = systemAddresses;
94 		this.pingId = pingId;
95 		this.serverId = serverId;
96 	}
97 
98 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
99 		_buffer.length = 0;
100 		static if(writeId){ writeBigEndianUbyte(ID); }
101 		clientAddress.encode(bufferInstance);
102 		writeBigEndianUshort(mtuLength);
103 		foreach(cldvqrcv;systemAddresses){ cldvqrcv.encode(bufferInstance); }
104 		writeBigEndianLong(pingId);
105 		writeBigEndianLong(serverId);
106 		return _buffer;
107 	}
108 
109 	public pure nothrow @safe void decode(bool readId=true)() {
110 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
111 		clientAddress.decode(bufferInstance);
112 		mtuLength=readBigEndianUshort();
113 		foreach(ref cldvqrcv;systemAddresses){ cldvqrcv.decode(bufferInstance); }
114 		pingId=readBigEndianLong();
115 		serverId=readBigEndianLong();
116 	}
117 
118 	public static pure nothrow @safe ServerHandshake fromBuffer(bool readId=true)(ubyte[] buffer) {
119 		ServerHandshake ret = new ServerHandshake();
120 		ret._buffer = buffer;
121 		ret.decode!readId();
122 		return ret;
123 	}
124 
125 	public override string toString() {
126 		return "ServerHandshake(clientAddress: " ~ std.conv.to!string(this.clientAddress) ~ ", mtuLength: " ~ std.conv.to!string(this.mtuLength) ~ ", systemAddresses: " ~ std.conv.to!string(this.systemAddresses) ~ ", pingId: " ~ std.conv.to!string(this.pingId) ~ ", serverId: " ~ std.conv.to!string(this.serverId) ~ ")";
127 	}
128 
129 }
130 
131 class ClientHandshake : Buffer {
132 
133 	public enum ubyte ID = 19;
134 
135 	public enum bool CLIENTBOUND = false;
136 	public enum bool SERVERBOUND = true;
137 
138 	public enum string[] FIELDS = ["clientAddress", "systemAddresses", "pingId", "clientId"];
139 
140 	public sul.protocol.raknet8.types.Address clientAddress;
141 	public sul.protocol.raknet8.types.Address[10] systemAddresses;
142 	public long pingId;
143 	public long clientId;
144 
145 	public pure nothrow @safe @nogc this() {}
146 
147 	public pure nothrow @safe @nogc this(sul.protocol.raknet8.types.Address clientAddress, sul.protocol.raknet8.types.Address[10] systemAddresses=(sul.protocol.raknet8.types.Address[10]).init, long pingId=long.init, long clientId=long.init) {
148 		this.clientAddress = clientAddress;
149 		this.systemAddresses = systemAddresses;
150 		this.pingId = pingId;
151 		this.clientId = clientId;
152 	}
153 
154 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
155 		_buffer.length = 0;
156 		static if(writeId){ writeBigEndianUbyte(ID); }
157 		clientAddress.encode(bufferInstance);
158 		foreach(cldvqrcv;systemAddresses){ cldvqrcv.encode(bufferInstance); }
159 		writeBigEndianLong(pingId);
160 		writeBigEndianLong(clientId);
161 		return _buffer;
162 	}
163 
164 	public pure nothrow @safe void decode(bool readId=true)() {
165 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
166 		clientAddress.decode(bufferInstance);
167 		foreach(ref cldvqrcv;systemAddresses){ cldvqrcv.decode(bufferInstance); }
168 		pingId=readBigEndianLong();
169 		clientId=readBigEndianLong();
170 	}
171 
172 	public static pure nothrow @safe ClientHandshake fromBuffer(bool readId=true)(ubyte[] buffer) {
173 		ClientHandshake ret = new ClientHandshake();
174 		ret._buffer = buffer;
175 		ret.decode!readId();
176 		return ret;
177 	}
178 
179 	public override string toString() {
180 		return "ClientHandshake(clientAddress: " ~ std.conv.to!string(this.clientAddress) ~ ", systemAddresses: " ~ std.conv.to!string(this.systemAddresses) ~ ", pingId: " ~ std.conv.to!string(this.pingId) ~ ", clientId: " ~ std.conv.to!string(this.clientId) ~ ")";
181 	}
182 
183 }
184 
185 class ClientCancelConnection : Buffer {
186 
187 	public enum ubyte ID = 21;
188 
189 	public enum bool CLIENTBOUND = false;
190 	public enum bool SERVERBOUND = true;
191 
192 	public enum string[] FIELDS = [];
193 
194 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
195 		_buffer.length = 0;
196 		static if(writeId){ writeBigEndianUbyte(ID); }
197 		return _buffer;
198 	}
199 
200 	public pure nothrow @safe void decode(bool readId=true)() {
201 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
202 	}
203 
204 	public static pure nothrow @safe ClientCancelConnection fromBuffer(bool readId=true)(ubyte[] buffer) {
205 		ClientCancelConnection ret = new ClientCancelConnection();
206 		ret._buffer = buffer;
207 		ret.decode!readId();
208 		return ret;
209 	}
210 
211 	public override string toString() {
212 		return "ClientCancelConnection()";
213 	}
214 
215 }
216 
217 class Ping : Buffer {
218 
219 	public enum ubyte ID = 0;
220 
221 	public enum bool CLIENTBOUND = false;
222 	public enum bool SERVERBOUND = true;
223 
224 	public enum string[] FIELDS = ["time"];
225 
226 	public long time;
227 
228 	public pure nothrow @safe @nogc this() {}
229 
230 	public pure nothrow @safe @nogc this(long time) {
231 		this.time = time;
232 	}
233 
234 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
235 		_buffer.length = 0;
236 		static if(writeId){ writeBigEndianUbyte(ID); }
237 		writeBigEndianLong(time);
238 		return _buffer;
239 	}
240 
241 	public pure nothrow @safe void decode(bool readId=true)() {
242 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
243 		time=readBigEndianLong();
244 	}
245 
246 	public static pure nothrow @safe Ping fromBuffer(bool readId=true)(ubyte[] buffer) {
247 		Ping ret = new Ping();
248 		ret._buffer = buffer;
249 		ret.decode!readId();
250 		return ret;
251 	}
252 
253 	public override string toString() {
254 		return "Ping(time: " ~ std.conv.to!string(this.time) ~ ")";
255 	}
256 
257 }
258 
259 class Pong : Buffer {
260 
261 	public enum ubyte ID = 3;
262 
263 	public enum bool CLIENTBOUND = true;
264 	public enum bool SERVERBOUND = false;
265 
266 	public enum string[] FIELDS = ["time"];
267 
268 	public long time;
269 
270 	public pure nothrow @safe @nogc this() {}
271 
272 	public pure nothrow @safe @nogc this(long time) {
273 		this.time = time;
274 	}
275 
276 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
277 		_buffer.length = 0;
278 		static if(writeId){ writeBigEndianUbyte(ID); }
279 		writeBigEndianLong(time);
280 		return _buffer;
281 	}
282 
283 	public pure nothrow @safe void decode(bool readId=true)() {
284 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
285 		time=readBigEndianLong();
286 	}
287 
288 	public static pure nothrow @safe Pong fromBuffer(bool readId=true)(ubyte[] buffer) {
289 		Pong ret = new Pong();
290 		ret._buffer = buffer;
291 		ret.decode!readId();
292 		return ret;
293 	}
294 
295 	public override string toString() {
296 		return "Pong(time: " ~ std.conv.to!string(this.time) ~ ")";
297 	}
298 
299 }
300 
301 class Mcpe : Buffer {
302 
303 	public enum ubyte ID = 254;
304 
305 	public enum bool CLIENTBOUND = true;
306 	public enum bool SERVERBOUND = true;
307 
308 	public enum string[] FIELDS = ["packet"];
309 
310 	public ubyte[] packet;
311 
312 	public pure nothrow @safe @nogc this() {}
313 
314 	public pure nothrow @safe @nogc this(ubyte[] packet) {
315 		this.packet = packet;
316 	}
317 
318 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
319 		_buffer.length = 0;
320 		static if(writeId){ writeBigEndianUbyte(ID); }
321 		writeBytes(packet);
322 		return _buffer;
323 	}
324 
325 	public pure nothrow @safe void decode(bool readId=true)() {
326 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
327 		packet=_buffer[_index..$].dup; _index=_buffer.length;
328 	}
329 
330 	public static pure nothrow @safe Mcpe fromBuffer(bool readId=true)(ubyte[] buffer) {
331 		Mcpe ret = new Mcpe();
332 		ret._buffer = buffer;
333 		ret.decode!readId();
334 		return ret;
335 	}
336 
337 	public override string toString() {
338 		return "Mcpe(packet: " ~ std.conv.to!string(this.packet) ~ ")";
339 	}
340 
341 }
342