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/hncom2.xml
8  */
9 module sul.protocol.hncom2.panel;
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.hncom2.types;
22 
23 static if(__traits(compiles, { import sul.metadata.hncom2; })) import sul.metadata.hncom2;
24 
25 alias Packets = TypeTuple!(Connection);
26 
27 class Connection : Buffer {
28 
29 	public enum ubyte ID = 36;
30 
31 	public enum bool CLIENTBOUND = true;
32 	public enum bool SERVERBOUND = false;
33 
34 	public enum string[] FIELDS = ["hash", "address", "worldId"];
35 
36 	public ubyte[64] hash;
37 	public ubyte[] address;
38 	public uint worldId;
39 
40 	public pure nothrow @safe @nogc this() {}
41 
42 	public pure nothrow @safe @nogc this(ubyte[64] hash, ubyte[] address=(ubyte[]).init, uint worldId=uint.init) {
43 		this.hash = hash;
44 		this.address = address;
45 		this.worldId = worldId;
46 	}
47 
48 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
49 		_buffer.length = 0;
50 		static if(writeId){ writeBigEndianUbyte(ID); }
51 		writeBytes(hash);
52 		writeBytes(varuint.encode(cast(uint)address.length)); writeBytes(address);
53 		writeBytes(varuint.encode(worldId));
54 		return _buffer;
55 	}
56 
57 	public pure nothrow @safe void decode(bool readId=true)() {
58 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
59 		if(_buffer.length>=_index+hash.length){ hash=_buffer[_index.._index+hash.length].dup; _index+=hash.length; }
60 		address.length=varuint.decode(_buffer, &_index); if(_buffer.length>=_index+address.length){ address=_buffer[_index.._index+address.length].dup; _index+=address.length; }
61 		worldId=varuint.decode(_buffer, &_index);
62 	}
63 
64 	public static pure nothrow @safe Connection fromBuffer(bool readId=true)(ubyte[] buffer) {
65 		Connection ret = new Connection();
66 		ret._buffer = buffer;
67 		ret.decode!readId();
68 		return ret;
69 	}
70 
71 	public override string toString() {
72 		return "Connection(hash: " ~ std.conv.to!string(this.hash) ~ ", address: " ~ std.conv.to!string(this.address) ~ ", worldId: " ~ std.conv.to!string(this.worldId) ~ ")";
73 	}
74 
75 }
76