-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (29 loc) · 821 Bytes
/
index.js
File metadata and controls
31 lines (29 loc) · 821 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
const Request = require('./messages/Request').Request;
const Response = require('./messages/Response').Response;
const PBF = require('pbf');
const responseDecodingBuffer = new Uint8Array(128);
const requestDecodingBuffer = new Uint8Array(128);
module.exports = {
Response: {
decode(buffer) {
const pbf = new PBF(buffer, buffer.length);
return Response.read(pbf);
},
encode(obj) {
const pbf = new PBF(responseDecodingBuffer);
Response.write(obj, pbf);
return new Buffer(pbf.finish());
}
},
Request: {
decode(buffer) {
const pbf = new PBF(buffer);
return Request.read(pbf, buffer.length);
},
encode(obj) {
const pbf = new PBF(requestDecodingBuffer);
Request.write(obj, pbf);
return new Buffer(pbf.finish());
}
}
};