-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEugProtocol.js
More file actions
34 lines (33 loc) · 768 Bytes
/
Copy pathEugProtocol.js
File metadata and controls
34 lines (33 loc) · 768 Bytes
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
31
32
33
34
/**
* @class
*/
class EugProtocol {
/**@constructor */
constructor(){}
/**
*
* @param {Buffer} data
*/
FromBuffer(data){
var pos = 0;
/**@type {number} */
this.CommandLen = data.readUIntBE(pos,2); pos+=2;
/**@type {number} */
this.CommandCode = data.readUIntBE(pos, 1); pos+=1;
/**@type {Buffer} */
this.Left = data.slice(pos, this.CommandLen+2);
}
/**
* @returns {Buffer}
*/
getBuffer(){
var length = 3 + this.Left.length;
var buf = new Buffer(length);
var pos = 0;
buf.writeUIntBE(length-2, pos, 2); pos+=2; // CommandLen
buf.writeUIntBE(0xE1, pos, 1); pos+=1; // CommandCode
this.Left.copy(buf, pos);
return buf;
}
}
module.exports = EugProtocol