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.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.raknet8; })) import sul.metadata.raknet8; 21 22 struct Address { 23 24 public enum string[] FIELDS = ["type", "ipv4", "ipv6", "unknown3", "port"]; 25 26 public ubyte type; 27 public uint ipv4; 28 public ubyte[16] ipv6; 29 public ubyte[10] unknown3; 30 public ushort port; 31 32 public pure nothrow @safe void encode(Buffer buffer) { 33 with(buffer) { 34 writeBigEndianUbyte(type); 35 if(type==4){ writeBigEndianUint(ipv4); } 36 if(type==6){ writeBytes(ipv6); } 37 if(type==6){ writeBytes(unknown3); } 38 writeBigEndianUshort(port); 39 } 40 } 41 42 public pure nothrow @safe void decode(Buffer buffer) { 43 with(buffer) { 44 type=readBigEndianUbyte(); 45 if(type==4){ ipv4=readBigEndianUint(); } 46 if(type==6){ if(_buffer.length>=_index+ipv6.length){ ipv6=_buffer[_index.._index+ipv6.length].dup; _index+=ipv6.length; } } 47 if(type==6){ if(_buffer.length>=_index+unknown3.length){ unknown3=_buffer[_index.._index+unknown3.length].dup; _index+=unknown3.length; } } 48 port=readBigEndianUshort(); 49 } 50 } 51 52 public string toString() { 53 return "Address(type: " ~ std.conv.to!string(this.type) ~ ", ipv4: " ~ std.conv.to!string(this.ipv4) ~ ", ipv6: " ~ std.conv.to!string(this.ipv6) ~ ", unknown3: " ~ std.conv.to!string(this.unknown3) ~ ", port: " ~ std.conv.to!string(this.port) ~ ")"; 54 } 55 56 } 57 58 struct Acknowledge { 59 60 public enum string[] FIELDS = ["unique", "first", "last"]; 61 62 public bool unique; 63 public int first; 64 public int last; 65 66 public pure nothrow @safe void encode(Buffer buffer) { 67 with(buffer) { 68 writeBigEndianBool(unique); 69 writeLittleEndianTriad(first); 70 if(unique==false){ writeLittleEndianTriad(last); } 71 } 72 } 73 74 public pure nothrow @safe void decode(Buffer buffer) { 75 with(buffer) { 76 unique=readBigEndianBool(); 77 first=readLittleEndianTriad(); 78 if(unique==false){ last=readLittleEndianTriad(); } 79 } 80 } 81 82 public string toString() { 83 return "Acknowledge(unique: " ~ std.conv.to!string(this.unique) ~ ", first: " ~ std.conv.to!string(this.first) ~ ", last: " ~ std.conv.to!string(this.last) ~ ")"; 84 } 85 86 } 87 88 struct Encapsulation { 89 90 public enum string[] FIELDS = ["info", "length", "messageIndex", "orderIndex", "orderChannel", "split", "payload"]; 91 92 public ubyte info; 93 public ushort length; 94 public int messageIndex; 95 public int orderIndex; 96 public ubyte orderChannel; 97 public sul.protocol.raknet8.types.Split split; 98 public ubyte[] payload; 99 100 public pure nothrow @safe void encode(Buffer buffer) { 101 with(buffer) { 102 writeBigEndianUbyte(info); 103 writeBigEndianUshort(length); 104 if((info&0x7F)>=64){ writeLittleEndianTriad(messageIndex); } 105 if((info&0x7F)>=96){ writeLittleEndianTriad(orderIndex); } 106 if((info&0x7F)>=96){ writeBigEndianUbyte(orderChannel); } 107 if((info&0x10)!=0){ split.encode(bufferInstance); } 108 writeBytes(payload); 109 } 110 } 111 112 public pure nothrow @safe void decode(Buffer buffer) { 113 with(buffer) { 114 info=readBigEndianUbyte(); 115 length=readBigEndianUshort(); 116 if((info&0x7F)>=64){ messageIndex=readLittleEndianTriad(); } 117 if((info&0x7F)>=96){ orderIndex=readLittleEndianTriad(); } 118 if((info&0x7F)>=96){ orderChannel=readBigEndianUbyte(); } 119 if((info&0x10)!=0){ split.decode(bufferInstance); } 120 payload=_buffer[_index..$].dup; _index=_buffer.length; 121 } 122 } 123 124 public string toString() { 125 return "Encapsulation(info: " ~ std.conv.to!string(this.info) ~ ", length: " ~ std.conv.to!string(this.length) ~ ", messageIndex: " ~ std.conv.to!string(this.messageIndex) ~ ", orderIndex: " ~ std.conv.to!string(this.orderIndex) ~ ", orderChannel: " ~ std.conv.to!string(this.orderChannel) ~ ", split: " ~ std.conv.to!string(this.split) ~ ", payload: " ~ std.conv.to!string(this.payload) ~ ")"; 126 } 127 128 } 129 130 struct Split { 131 132 public enum string[] FIELDS = ["count", "id", "order"]; 133 134 public uint count; 135 public ushort id; 136 public uint order; 137 138 public pure nothrow @safe void encode(Buffer buffer) { 139 with(buffer) { 140 writeBigEndianUint(count); 141 writeBigEndianUshort(id); 142 writeBigEndianUint(order); 143 } 144 } 145 146 public pure nothrow @safe void decode(Buffer buffer) { 147 with(buffer) { 148 count=readBigEndianUint(); 149 id=readBigEndianUshort(); 150 order=readBigEndianUint(); 151 } 152 } 153 154 public string toString() { 155 return "Split(count: " ~ std.conv.to!string(this.count) ~ ", id: " ~ std.conv.to!string(this.id) ~ ", order: " ~ std.conv.to!string(this.order) ~ ")"; 156 } 157 158 } 159