1 /*
2 * MsgTrans - Message Transport Framework for DLang. Based on TCP, WebSocket, UDP transmission protocol.
3 *
4 * Copyright (C) 2019 HuntLabs
5 *
6 * Website: https://www.msgtrans.org
7 *
8 * Licensed under the Apache-2.0 License.
9 *
10 */
11
12 module msgtrans.MessageBuffer;
13
14 import std.format;
15 import std.bitmanip;
16
17 /**
18 *
19 */
20 class MessageBuffer
21 {
22 uint id;
23 ubyte compression;
24 uint extendLength;
25 ubyte[] data;
26 ubyte[] extend;
27 bool hasExtend;
28
29 this() {
30 id = 0;
31 compression = 0;
32 hasExtend = false;
33 extendLength = 0;
34 }
35
36
37 this(uint id, string data) {
38 this(id, cast(ubyte[])data.dup);
39 }
40
41 this(uint id, ubyte[] data) {
42 this.id = id;
43 this.data = data;
44 hasExtend = false;
45 this.extendLength = 0;
46 }
47
48 this(uint id, ubyte[] data , ubyte[] extend) {
49 this.id = id;
50 this.data = data;
51 //this.extend = extend;
52 this.extendLength = cast(int)(extend.length);
53 //this.extend = new ubyte[extendLength];
54 this.extend = extend;
55 hasExtend = true;
56
57 }
58
59 //this(uint id, ubyte[] data, uint tagId, uint clientId)
60 //{
61 // this.id = id;
62 // this.data = data;
63 // this.tagId = tagId;
64 // this.extendLength = uint.sizeof + uint.sizeof;
65 // this.clientId = clientId;
66 //}
67
68 override string toString() {
69 return format("id: %d, length: %d", id, data.length);
70 }
71 }