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.control; 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!(Ack, Nack, Encapsulated); 26 27 class Ack : Buffer { 28 29 public enum ubyte ID = 192; 30 31 public enum bool CLIENTBOUND = true; 32 public enum bool SERVERBOUND = true; 33 34 public enum string[] FIELDS = ["packets"]; 35 36 public sul.protocol.raknet8.types.Acknowledge[] packets; 37 38 public pure nothrow @safe @nogc this() {} 39 40 public pure nothrow @safe @nogc this(sul.protocol.raknet8.types.Acknowledge[] packets) { 41 this.packets = packets; 42 } 43 44 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 45 _buffer.length = 0; 46 static if(writeId){ writeBigEndianUbyte(ID); } 47 writeBigEndianUshort(cast(ushort)packets.length); foreach(cfavc;packets){ cfavc.encode(bufferInstance); } 48 return _buffer; 49 } 50 51 public pure nothrow @safe void decode(bool readId=true)() { 52 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 53 packets.length=readBigEndianUshort(); foreach(ref cfavc;packets){ cfavc.decode(bufferInstance); } 54 } 55 56 public static pure nothrow @safe Ack fromBuffer(bool readId=true)(ubyte[] buffer) { 57 Ack ret = new Ack(); 58 ret._buffer = buffer; 59 ret.decode!readId(); 60 return ret; 61 } 62 63 public override string toString() { 64 return "Ack(packets: " ~ std.conv.to!string(this.packets) ~ ")"; 65 } 66 67 } 68 69 class Nack : Buffer { 70 71 public enum ubyte ID = 160; 72 73 public enum bool CLIENTBOUND = true; 74 public enum bool SERVERBOUND = true; 75 76 public enum string[] FIELDS = ["packets"]; 77 78 public sul.protocol.raknet8.types.Acknowledge[] packets; 79 80 public pure nothrow @safe @nogc this() {} 81 82 public pure nothrow @safe @nogc this(sul.protocol.raknet8.types.Acknowledge[] packets) { 83 this.packets = packets; 84 } 85 86 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 87 _buffer.length = 0; 88 static if(writeId){ writeBigEndianUbyte(ID); } 89 writeBigEndianUshort(cast(ushort)packets.length); foreach(cfavc;packets){ cfavc.encode(bufferInstance); } 90 return _buffer; 91 } 92 93 public pure nothrow @safe void decode(bool readId=true)() { 94 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 95 packets.length=readBigEndianUshort(); foreach(ref cfavc;packets){ cfavc.decode(bufferInstance); } 96 } 97 98 public static pure nothrow @safe Nack fromBuffer(bool readId=true)(ubyte[] buffer) { 99 Nack ret = new Nack(); 100 ret._buffer = buffer; 101 ret.decode!readId(); 102 return ret; 103 } 104 105 public override string toString() { 106 return "Nack(packets: " ~ std.conv.to!string(this.packets) ~ ")"; 107 } 108 109 } 110 111 class Encapsulated : Buffer { 112 113 public enum ubyte ID = 132; 114 115 public enum bool CLIENTBOUND = true; 116 public enum bool SERVERBOUND = true; 117 118 public enum string[] FIELDS = ["count", "encapsulation"]; 119 120 public int count; 121 public sul.protocol.raknet8.types.Encapsulation encapsulation; 122 123 public pure nothrow @safe @nogc this() {} 124 125 public pure nothrow @safe @nogc this(int count, sul.protocol.raknet8.types.Encapsulation encapsulation=sul.protocol.raknet8.types.Encapsulation.init) { 126 this.count = count; 127 this.encapsulation = encapsulation; 128 } 129 130 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 131 _buffer.length = 0; 132 static if(writeId){ writeBigEndianUbyte(ID); } 133 writeLittleEndianTriad(count); 134 encapsulation.encode(bufferInstance); 135 return _buffer; 136 } 137 138 public pure nothrow @safe void decode(bool readId=true)() { 139 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 140 count=readLittleEndianTriad(); 141 encapsulation.decode(bufferInstance); 142 } 143 144 public static pure nothrow @safe Encapsulated fromBuffer(bool readId=true)(ubyte[] buffer) { 145 Encapsulated ret = new Encapsulated(); 146 ret._buffer = buffer; 147 ret.decode!readId(); 148 return ret; 149 } 150 151 public override string toString() { 152 return "Encapsulated(count: " ~ std.conv.to!string(this.count) ~ ", encapsulation: " ~ std.conv.to!string(this.encapsulation) ~ ")"; 153 } 154 155 } 156