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/java335.xml 8 */ 9 module sul.protocol.java335.status; 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.java335.types; 22 23 static if(__traits(compiles, { import sul.metadata.java335; })) import sul.metadata.java335; 24 25 alias Packets = TypeTuple!(Handshake, Request, Response, Latency); 26 27 class Handshake : Buffer { 28 29 public enum uint ID = 0; 30 31 public enum bool CLIENTBOUND = false; 32 public enum bool SERVERBOUND = true; 33 34 // next 35 public enum uint STATUS = 1; 36 public enum uint LOGIN = 2; 37 38 public enum string[] FIELDS = ["protocol", "serverAddress", "serverPort", "next"]; 39 40 public uint protocol = 335; 41 public string serverAddress; 42 public ushort serverPort; 43 public uint next; 44 45 public pure nothrow @safe @nogc this() {} 46 47 public pure nothrow @safe @nogc this(uint protocol, string serverAddress=string.init, ushort serverPort=ushort.init, uint next=uint.init) { 48 this.protocol = protocol; 49 this.serverAddress = serverAddress; 50 this.serverPort = serverPort; 51 this.next = next; 52 } 53 54 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 55 _buffer.length = 0; 56 static if(writeId){ writeBytes(varuint.encode(ID)); } 57 writeBytes(varuint.encode(protocol)); 58 writeBytes(varuint.encode(cast(uint)serverAddress.length)); writeString(serverAddress); 59 writeBigEndianUshort(serverPort); 60 writeBytes(varuint.encode(next)); 61 return _buffer; 62 } 63 64 public pure nothrow @safe void decode(bool readId=true)() { 65 static if(readId){ uint _id; _id=varuint.decode(_buffer, &_index); } 66 protocol=varuint.decode(_buffer, &_index); 67 uint cvdvqrcv=varuint.decode(_buffer, &_index); serverAddress=readString(cvdvqrcv); 68 serverPort=readBigEndianUshort(); 69 next=varuint.decode(_buffer, &_index); 70 } 71 72 public static pure nothrow @safe Handshake fromBuffer(bool readId=true)(ubyte[] buffer) { 73 Handshake ret = new Handshake(); 74 ret._buffer = buffer; 75 ret.decode!readId(); 76 return ret; 77 } 78 79 public override string toString() { 80 return "Handshake(protocol: " ~ std.conv.to!string(this.protocol) ~ ", serverAddress: " ~ std.conv.to!string(this.serverAddress) ~ ", serverPort: " ~ std.conv.to!string(this.serverPort) ~ ", next: " ~ std.conv.to!string(this.next) ~ ")"; 81 } 82 83 } 84 85 class Request : Buffer { 86 87 public enum uint ID = 0; 88 89 public enum bool CLIENTBOUND = false; 90 public enum bool SERVERBOUND = true; 91 92 public enum string[] FIELDS = []; 93 94 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 95 _buffer.length = 0; 96 static if(writeId){ writeBytes(varuint.encode(ID)); } 97 return _buffer; 98 } 99 100 public pure nothrow @safe void decode(bool readId=true)() { 101 static if(readId){ uint _id; _id=varuint.decode(_buffer, &_index); } 102 } 103 104 public static pure nothrow @safe Request fromBuffer(bool readId=true)(ubyte[] buffer) { 105 Request ret = new Request(); 106 ret._buffer = buffer; 107 ret.decode!readId(); 108 return ret; 109 } 110 111 public override string toString() { 112 return "Request()"; 113 } 114 115 } 116 117 class Response : Buffer { 118 119 public enum uint ID = 0; 120 121 public enum bool CLIENTBOUND = true; 122 public enum bool SERVERBOUND = false; 123 124 public enum string[] FIELDS = ["json"]; 125 126 public string json; 127 128 public pure nothrow @safe @nogc this() {} 129 130 public pure nothrow @safe @nogc this(string json) { 131 this.json = json; 132 } 133 134 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 135 _buffer.length = 0; 136 static if(writeId){ writeBytes(varuint.encode(ID)); } 137 writeBytes(varuint.encode(cast(uint)json.length)); writeString(json); 138 return _buffer; 139 } 140 141 public pure nothrow @safe void decode(bool readId=true)() { 142 static if(readId){ uint _id; _id=varuint.decode(_buffer, &_index); } 143 uint anb=varuint.decode(_buffer, &_index); json=readString(anb); 144 } 145 146 public static pure nothrow @safe Response fromBuffer(bool readId=true)(ubyte[] buffer) { 147 Response ret = new Response(); 148 ret._buffer = buffer; 149 ret.decode!readId(); 150 return ret; 151 } 152 153 public override string toString() { 154 return "Response(json: " ~ std.conv.to!string(this.json) ~ ")"; 155 } 156 157 } 158 159 class Latency : Buffer { 160 161 public enum uint ID = 1; 162 163 public enum bool CLIENTBOUND = true; 164 public enum bool SERVERBOUND = true; 165 166 public enum string[] FIELDS = ["id"]; 167 168 public long id; 169 170 public pure nothrow @safe @nogc this() {} 171 172 public pure nothrow @safe @nogc this(long id) { 173 this.id = id; 174 } 175 176 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 177 _buffer.length = 0; 178 static if(writeId){ writeBytes(varuint.encode(ID)); } 179 writeBigEndianLong(id); 180 return _buffer; 181 } 182 183 public pure nothrow @safe void decode(bool readId=true)() { 184 static if(readId){ uint _id; _id=varuint.decode(_buffer, &_index); } 185 id=readBigEndianLong(); 186 } 187 188 public static pure nothrow @safe Latency fromBuffer(bool readId=true)(ubyte[] buffer) { 189 Latency ret = new Latency(); 190 ret._buffer = buffer; 191 ret.decode!readId(); 192 return ret; 193 } 194 195 public override string toString() { 196 return "Latency(id: " ~ std.conv.to!string(this.id) ~ ")"; 197 } 198 199 } 200