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/pocket102.xml
8  */
9 module sul.protocol.pocket102.types;
10 
11 import std.bitmanip : write, peek;
12 static import std.conv;
13 import std.system : Endian;
14 import std.typecons : Tuple;
15 import std.uuid : UUID;
16 
17 import sul.utils.buffer;
18 import sul.utils.var;
19 
20 static if(__traits(compiles, { import sul.metadata.pocket102; })) import sul.metadata.pocket102;
21 
22 struct PackWithSize {
23 
24 	public enum string[] FIELDS = ["id", "vers", "size"];
25 
26 	public string id;
27 	public string vers;
28 	public ulong size;
29 
30 	public pure nothrow @safe void encode(Buffer buffer) {
31 		with(buffer) {
32 			writeBytes(varuint.encode(cast(uint)id.length)); writeString(id);
33 			writeBytes(varuint.encode(cast(uint)vers.length)); writeString(vers);
34 			writeLittleEndianUlong(size);
35 		}
36 	}
37 
38 	public pure nothrow @safe void decode(Buffer buffer) {
39 		with(buffer) {
40 			uint aq=varuint.decode(_buffer, &_index); id=readString(aq);
41 			uint dvc=varuint.decode(_buffer, &_index); vers=readString(dvc);
42 			size=readLittleEndianUlong();
43 		}
44 	}
45 
46 	public string toString() {
47 		return "PackWithSize(id: " ~ std.conv.to!string(this.id) ~ ", vers: " ~ std.conv.to!string(this.vers) ~ ", size: " ~ std.conv.to!string(this.size) ~ ")";
48 	}
49 
50 }
51 
52 struct Pack {
53 
54 	public enum string[] FIELDS = ["id", "vers"];
55 
56 	public string id;
57 	public string vers;
58 
59 	public pure nothrow @safe void encode(Buffer buffer) {
60 		with(buffer) {
61 			writeBytes(varuint.encode(cast(uint)id.length)); writeString(id);
62 			writeBytes(varuint.encode(cast(uint)vers.length)); writeString(vers);
63 		}
64 	}
65 
66 	public pure nothrow @safe void decode(Buffer buffer) {
67 		with(buffer) {
68 			uint aq=varuint.decode(_buffer, &_index); id=readString(aq);
69 			uint dvc=varuint.decode(_buffer, &_index); vers=readString(dvc);
70 		}
71 	}
72 
73 	public string toString() {
74 		return "Pack(id: " ~ std.conv.to!string(this.id) ~ ", vers: " ~ std.conv.to!string(this.vers) ~ ")";
75 	}
76 
77 }
78 
79 struct Slot {
80 
81 	public enum string[] FIELDS = ["id", "metaAndCount", "nbt"];
82 
83 	public int id;
84 	public int metaAndCount;
85 	public ubyte[] nbt;
86 
87 	public pure nothrow @safe void encode(Buffer buffer) {
88 		with(buffer) {
89 			writeBytes(varint.encode(id));
90 			if(id>0){ writeBytes(varint.encode(metaAndCount)); }
91 			if(id>0){ writeLittleEndianUshort(cast(ushort)nbt.length); writeBytes(nbt); }
92 		}
93 	}
94 
95 	public pure nothrow @safe void decode(Buffer buffer) {
96 		with(buffer) {
97 			id=varint.decode(_buffer, &_index);
98 			if(id>0){ metaAndCount=varint.decode(_buffer, &_index); }
99 			if(id>0){ nbt.length=readLittleEndianUshort(); if(_buffer.length>=_index+nbt.length){ nbt=_buffer[_index.._index+nbt.length].dup; _index+=nbt.length; } }
100 		}
101 	}
102 
103 	public string toString() {
104 		return "Slot(id: " ~ std.conv.to!string(this.id) ~ ", metaAndCount: " ~ std.conv.to!string(this.metaAndCount) ~ ", nbt: " ~ std.conv.to!string(this.nbt) ~ ")";
105 	}
106 
107 }
108 
109 struct Attribute {
110 
111 	public enum string[] FIELDS = ["min", "max", "value", "def", "name"];
112 
113 	public float min;
114 	public float max;
115 	public float value;
116 	public float def;
117 	public string name;
118 
119 	public pure nothrow @safe void encode(Buffer buffer) {
120 		with(buffer) {
121 			writeLittleEndianFloat(min);
122 			writeLittleEndianFloat(max);
123 			writeLittleEndianFloat(value);
124 			writeLittleEndianFloat(def);
125 			writeBytes(varuint.encode(cast(uint)name.length)); writeString(name);
126 		}
127 	}
128 
129 	public pure nothrow @safe void decode(Buffer buffer) {
130 		with(buffer) {
131 			min=readLittleEndianFloat();
132 			max=readLittleEndianFloat();
133 			value=readLittleEndianFloat();
134 			def=readLittleEndianFloat();
135 			uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz);
136 		}
137 	}
138 
139 	public string toString() {
140 		return "Attribute(min: " ~ std.conv.to!string(this.min) ~ ", max: " ~ std.conv.to!string(this.max) ~ ", value: " ~ std.conv.to!string(this.value) ~ ", def: " ~ std.conv.to!string(this.def) ~ ", name: " ~ std.conv.to!string(this.name) ~ ")";
141 	}
142 
143 }
144 
145 struct BlockPosition {
146 
147 	public enum string[] FIELDS = ["x", "y", "z"];
148 
149 	public int x;
150 	public uint y;
151 	public int z;
152 
153 	public pure nothrow @safe void encode(Buffer buffer) {
154 		with(buffer) {
155 			writeBytes(varint.encode(x));
156 			writeBytes(varuint.encode(y));
157 			writeBytes(varint.encode(z));
158 		}
159 	}
160 
161 	public pure nothrow @safe void decode(Buffer buffer) {
162 		with(buffer) {
163 			x=varint.decode(_buffer, &_index);
164 			y=varuint.decode(_buffer, &_index);
165 			z=varint.decode(_buffer, &_index);
166 		}
167 	}
168 
169 	public string toString() {
170 		return "BlockPosition(x: " ~ std.conv.to!string(this.x) ~ ", y: " ~ std.conv.to!string(this.y) ~ ", z: " ~ std.conv.to!string(this.z) ~ ")";
171 	}
172 
173 }
174 
175 struct Skin {
176 
177 	public enum string[] FIELDS = ["name", "data"];
178 
179 	public string name;
180 	public ubyte[] data;
181 
182 	public pure nothrow @safe void encode(Buffer buffer) {
183 		with(buffer) {
184 			writeBytes(varuint.encode(cast(uint)name.length)); writeString(name);
185 			writeBytes(varuint.encode(cast(uint)data.length)); writeBytes(data);
186 		}
187 	}
188 
189 	public pure nothrow @safe void decode(Buffer buffer) {
190 		with(buffer) {
191 			uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz);
192 			data.length=varuint.decode(_buffer, &_index); if(_buffer.length>=_index+data.length){ data=_buffer[_index.._index+data.length].dup; _index+=data.length; }
193 		}
194 	}
195 
196 	public string toString() {
197 		return "Skin(name: " ~ std.conv.to!string(this.name) ~ ", data: " ~ std.conv.to!string(this.data) ~ ")";
198 	}
199 
200 }
201 
202 struct PlayerList {
203 
204 	public enum string[] FIELDS = ["uuid", "entityId", "displayName", "skin"];
205 
206 	public UUID uuid;
207 	public long entityId;
208 	public string displayName;
209 	public sul.protocol.pocket102.types.Skin skin;
210 
211 	public pure nothrow @safe void encode(Buffer buffer) {
212 		with(buffer) {
213 			writeBytes(uuid.data);
214 			writeBytes(varlong.encode(entityId));
215 			writeBytes(varuint.encode(cast(uint)displayName.length)); writeString(displayName);
216 			skin.encode(bufferInstance);
217 		}
218 	}
219 
220 	public pure nothrow @safe void decode(Buffer buffer) {
221 		with(buffer) {
222 			if(_buffer.length>=_index+16){ ubyte[16] dvz=_buffer[_index.._index+16].dup; _index+=16; uuid=UUID(dvz); }
223 			entityId=varlong.decode(_buffer, &_index);
224 			uint zlcxe5bu=varuint.decode(_buffer, &_index); displayName=readString(zlcxe5bu);
225 			skin.decode(bufferInstance);
226 		}
227 	}
228 
229 	public string toString() {
230 		return "PlayerList(uuid: " ~ std.conv.to!string(this.uuid) ~ ", entityId: " ~ std.conv.to!string(this.entityId) ~ ", displayName: " ~ std.conv.to!string(this.displayName) ~ ", skin: " ~ std.conv.to!string(this.skin) ~ ")";
231 	}
232 
233 }
234 
235 struct Link {
236 
237 	// action
238 	public enum ubyte ADD = 0;
239 	public enum ubyte RIDE = 1;
240 	public enum ubyte REMOVE = 2;
241 
242 	public enum string[] FIELDS = ["from", "to", "action"];
243 
244 	public long from;
245 	public long to;
246 	public ubyte action;
247 
248 	public pure nothrow @safe void encode(Buffer buffer) {
249 		with(buffer) {
250 			writeBytes(varlong.encode(from));
251 			writeBytes(varlong.encode(to));
252 			writeBigEndianUbyte(action);
253 		}
254 	}
255 
256 	public pure nothrow @safe void decode(Buffer buffer) {
257 		with(buffer) {
258 			from=varlong.decode(_buffer, &_index);
259 			to=varlong.decode(_buffer, &_index);
260 			action=readBigEndianUbyte();
261 		}
262 	}
263 
264 	public string toString() {
265 		return "Link(from: " ~ std.conv.to!string(this.from) ~ ", to: " ~ std.conv.to!string(this.to) ~ ", action: " ~ std.conv.to!string(this.action) ~ ")";
266 	}
267 
268 }
269 
270 struct Recipe {
271 
272 	// type
273 	public enum int SHAPELESS = 0;
274 	public enum int SHAPED = 1;
275 	public enum int FURNACE = 2;
276 	public enum int FURNACE_DATA = 3;
277 	public enum int MULTI = 4;
278 
279 	public enum string[] FIELDS = ["type", "data"];
280 
281 	public int type;
282 	public ubyte[] data;
283 
284 	public pure nothrow @safe void encode(Buffer buffer) {
285 		with(buffer) {
286 			writeBytes(varint.encode(type));
287 			writeBytes(data);
288 		}
289 	}
290 
291 	public pure nothrow @safe void decode(Buffer buffer) {
292 		with(buffer) {
293 			type=varint.decode(_buffer, &_index);
294 			data=_buffer[_index..$].dup; _index=_buffer.length;
295 		}
296 	}
297 
298 	public string toString() {
299 		return "Recipe(type: " ~ std.conv.to!string(this.type) ~ ", data: " ~ std.conv.to!string(this.data) ~ ")";
300 	}
301 
302 }
303 
304 struct ChunkData {
305 
306 	public enum string[] FIELDS = ["sections", "heights", "biomes", "borders", "extraData", "blockEntities"];
307 
308 	public sul.protocol.pocket102.types.Section[] sections;
309 	public ushort[256] heights;
310 	public ubyte[256] biomes;
311 	public ubyte[] borders;
312 	public sul.protocol.pocket102.types.ExtraData[] extraData;
313 	public ubyte[] blockEntities;
314 
315 	public pure nothrow @safe void encode(Buffer o_buffer) {
316 		Buffer buffer = new Buffer();
317 		with(buffer) {
318 			writeBytes(varuint.encode(cast(uint)sections.length)); foreach(cvdlbm;sections){ cvdlbm.encode(bufferInstance); }
319 			foreach(avzhc;heights){ writeBigEndianUshort(avzhc); }
320 			writeBytes(biomes);
321 			writeBytes(varuint.encode(cast(uint)borders.length)); writeBytes(borders);
322 			writeBytes(varuint.encode(cast(uint)extraData.length)); foreach(zhcfyr;extraData){ zhcfyr.encode(bufferInstance); }
323 			writeBytes(blockEntities);
324 		}
325 		with(o_buffer){ writeBytes(varuint.encode(cast(uint)buffer._buffer.length)); }
326 		o_buffer.writeBytes(buffer._buffer);
327 	}
328 
329 	public pure nothrow @safe void decode(Buffer o_buffer) {
330 		Buffer buffer = new Buffer();
331 		with(o_buffer) {
332 			immutable _length=varuint.decode(_buffer, &_index);
333 			buffer._buffer = readBytes(_length);
334 		}
335 		with(buffer) {
336 			sections.length=varuint.decode(_buffer, &_index); foreach(ref cvdlbm;sections){ cvdlbm.decode(bufferInstance); }
337 			foreach(ref avzhc;heights){ avzhc=readBigEndianUshort(); }
338 			if(_buffer.length>=_index+biomes.length){ biomes=_buffer[_index.._index+biomes.length].dup; _index+=biomes.length; }
339 			borders.length=varuint.decode(_buffer, &_index); if(_buffer.length>=_index+borders.length){ borders=_buffer[_index.._index+borders.length].dup; _index+=borders.length; }
340 			extraData.length=varuint.decode(_buffer, &_index); foreach(ref zhcfyr;extraData){ zhcfyr.decode(bufferInstance); }
341 			blockEntities=_buffer[_index..$].dup; _index=_buffer.length;
342 		}
343 	}
344 
345 	public string toString() {
346 		return "ChunkData(sections: " ~ std.conv.to!string(this.sections) ~ ", heights: " ~ std.conv.to!string(this.heights) ~ ", biomes: " ~ std.conv.to!string(this.biomes) ~ ", borders: " ~ std.conv.to!string(this.borders) ~ ", extraData: " ~ std.conv.to!string(this.extraData) ~ ", blockEntities: " ~ std.conv.to!string(this.blockEntities) ~ ")";
347 	}
348 
349 }
350 
351 struct Section {
352 
353 	public enum string[] FIELDS = ["storageVersion", "blockIds", "blockMetas", "skyLight", "blockLight"];
354 
355 	public ubyte storageVersion = 0;
356 	public ubyte[4096] blockIds;
357 	public ubyte[2048] blockMetas;
358 	public ubyte[2048] skyLight;
359 	public ubyte[2048] blockLight;
360 
361 	public pure nothrow @safe void encode(Buffer buffer) {
362 		with(buffer) {
363 			writeBigEndianUbyte(storageVersion);
364 			writeBytes(blockIds);
365 			writeBytes(blockMetas);
366 			writeBytes(skyLight);
367 			writeBytes(blockLight);
368 		}
369 	}
370 
371 	public pure nothrow @safe void decode(Buffer buffer) {
372 		with(buffer) {
373 			storageVersion=readBigEndianUbyte();
374 			if(_buffer.length>=_index+blockIds.length){ blockIds=_buffer[_index.._index+blockIds.length].dup; _index+=blockIds.length; }
375 			if(_buffer.length>=_index+blockMetas.length){ blockMetas=_buffer[_index.._index+blockMetas.length].dup; _index+=blockMetas.length; }
376 			if(_buffer.length>=_index+skyLight.length){ skyLight=_buffer[_index.._index+skyLight.length].dup; _index+=skyLight.length; }
377 			if(_buffer.length>=_index+blockLight.length){ blockLight=_buffer[_index.._index+blockLight.length].dup; _index+=blockLight.length; }
378 		}
379 	}
380 
381 	public string toString() {
382 		return "Section(storageVersion: " ~ std.conv.to!string(this.storageVersion) ~ ", blockIds: " ~ std.conv.to!string(this.blockIds) ~ ", blockMetas: " ~ std.conv.to!string(this.blockMetas) ~ ", skyLight: " ~ std.conv.to!string(this.skyLight) ~ ", blockLight: " ~ std.conv.to!string(this.blockLight) ~ ")";
383 	}
384 
385 }
386 
387 struct ExtraData {
388 
389 	public enum string[] FIELDS = ["key", "value"];
390 
391 	public uint key;
392 	public ushort value;
393 
394 	public pure nothrow @safe void encode(Buffer buffer) {
395 		with(buffer) {
396 			writeBytes(varuint.encode(key));
397 			writeLittleEndianUshort(value);
398 		}
399 	}
400 
401 	public pure nothrow @safe void decode(Buffer buffer) {
402 		with(buffer) {
403 			key=varuint.decode(_buffer, &_index);
404 			value=readLittleEndianUshort();
405 		}
406 	}
407 
408 	public string toString() {
409 		return "ExtraData(key: " ~ std.conv.to!string(this.key) ~ ", value: " ~ std.conv.to!string(this.value) ~ ")";
410 	}
411 
412 }
413 
414 struct Decoration {
415 
416 	public enum string[] FIELDS = ["rotationAndIcon", "position", "label", "color"];
417 
418 	public int rotationAndIcon;
419 	public Tuple!(ubyte, "x", ubyte, "z") position;
420 	public string label;
421 	public uint color;
422 
423 	public pure nothrow @safe void encode(Buffer buffer) {
424 		with(buffer) {
425 			writeBytes(varint.encode(rotationAndIcon));
426 			writeBigEndianUbyte(position.x); writeBigEndianUbyte(position.z);
427 			writeBytes(varuint.encode(cast(uint)label.length)); writeString(label);
428 			writeLittleEndianUint(color);
429 		}
430 	}
431 
432 	public pure nothrow @safe void decode(Buffer buffer) {
433 		with(buffer) {
434 			rotationAndIcon=varint.decode(_buffer, &_index);
435 			position.x=readBigEndianUbyte(); position.z=readBigEndianUbyte();
436 			uint bfzw=varuint.decode(_buffer, &_index); label=readString(bfzw);
437 			color=readLittleEndianUint();
438 		}
439 	}
440 
441 	public string toString() {
442 		return "Decoration(rotationAndIcon: " ~ std.conv.to!string(this.rotationAndIcon) ~ ", position: " ~ std.conv.to!string(this.position) ~ ", label: " ~ std.conv.to!string(this.label) ~ ", color: " ~ std.conv.to!string(this.color) ~ ")";
443 	}
444 
445 }
446 
447 struct Rule {
448 
449 	// name
450 	public enum string DROWNING_DAMAGE = "drowningdamage";
451 	public enum string FALL_DAMAGE = "falldamage";
452 	public enum string FIRE_DAMAGE = "firedamage";
453 	public enum string IMMUTABLE_WORLD = "immutableworld";
454 	public enum string PVP = "pvp";
455 
456 	public enum string[] FIELDS = ["name", "value", "unknown2"];
457 
458 	public string name;
459 	public bool value;
460 	public bool unknown2;
461 
462 	public pure nothrow @safe void encode(Buffer buffer) {
463 		with(buffer) {
464 			writeBytes(varuint.encode(cast(uint)name.length)); writeString(name);
465 			writeBigEndianBool(value);
466 			writeBigEndianBool(unknown2);
467 		}
468 	}
469 
470 	public pure nothrow @safe void decode(Buffer buffer) {
471 		with(buffer) {
472 			uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz);
473 			value=readBigEndianBool();
474 			unknown2=readBigEndianBool();
475 		}
476 	}
477 
478 	public string toString() {
479 		return "Rule(name: " ~ std.conv.to!string(this.name) ~ ", value: " ~ std.conv.to!string(this.value) ~ ", unknown2: " ~ std.conv.to!string(this.unknown2) ~ ")";
480 	}
481 
482 }
483