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