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