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 
21 
22 
23 class MessageBuffer
24 {
25     uint id;
26     ubyte compression;
27     uint extendLength;
28     ubyte[] data;
29     ubyte[] extend;
30     bool hasExtend;
31 
32     this()
33     {
34         id = 0;
35         compression = 0;
36         hasExtend = false;
37         extendLength = 0;
38     }
39 
40     this(uint id, ubyte[] data) {
41       this.id = id;
42       this.data = data;
43       hasExtend = false;
44       this.extendLength = 0;
45     }
46 
47     this(uint id, ubyte[] data , ubyte[] extend) {
48         this.id = id;
49         this.data = data;
50         //this.extend = extend;
51         this.extendLength = cast(int)(extend.length);
52         //this.extend = new ubyte[extendLength];
53         this.extend = extend;
54         hasExtend = true;
55 
56     }
57 
58     //this(uint id, ubyte[] data, uint tagId, uint clientId)
59     //{
60     //    this.id = id;
61     //    this.data = data;
62     //    this.tagId = tagId;
63     //    this.extendLength = uint.sizeof + uint.sizeof;
64     //    this.clientId = clientId;
65     //}
66 
67     override string toString() {
68         return format("id: %d, length: %d", id, data.length);
69     }
70 }