-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendmsg.js
30 lines (30 loc) · 870 Bytes
/
sendmsg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function SendMsg(a) {
this.len = 0;
this.dataView = new DataView(new ArrayBuffer(a));
this.writeUInt8 = function(a) {
this.dataView.setUint8(this.len, a);
this.len += 1
};
this.writeInt8 = function(a) {
this.dataView.setInt8(this.len, a, !1);
this.len += 1
};
this.writeUInt16 = function(a) {
this.dataView.setUint16(this.len, a, !1);
this.len += 2
};
this.writeInt16 = function(a) {
this.dataView.setInt16(this.len, a, !1);
this.len += 2
};
this.writeUInt32 = function(a) {
this.dataView.setUint32(this.len, a, !1);
this.len += 4
};
this.writeString = function(a) {
a = encode_utf8(a);
var len = a.length;
this.writeUInt16(a.length);
for (var c = 0; c < len; c++) this.writeUInt8(a.charCodeAt(c))
}
};