-
Notifications
You must be signed in to change notification settings - Fork 0
/
logicusercreator.js
48 lines (45 loc) · 1.26 KB
/
logicusercreator.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function createLogicUser (execlib, bufferlib) {
'use strict';
var lib = execlib.lib,
q = lib.q,
qlib = lib.qlib,
SynchronousLogic = bufferlib.SynchronousLogic;
function LogicUser(usernamearray) {
SynchronousLogic.call(this, usernamearray);
this.buffer = null;
this.offset = 0;
}
lib.inherit(LogicUser, SynchronousLogic);
LogicUser.prototype.destroy = function () {
this.offset = null;
this.buffer = null;
SynchronousLogic.prototype.destroy.call(this);
};
LogicUser.prototype.init = bufferlib.BufferUserBase.prototype.init;
/*
LogicUser.prototype.init = function (buffer, cursor) {
var b = this.buffer;
this.buffer = buffer;
this.cursor = cursor || 0;
console.trace();
console.log('LogicUser init offset', cursor, buffer, '=>', this.buffer);
};
*/
//LogicUser.prototype.process = bufferlib.BufferUserBase.prototype.process;
LogicUser.prototype.use = function () {
try {
var ret = this.decode(this.buffer.slice(this.cursor || 0));
if (ret) {
this.cursor += this.neededBytes(ret);
}
return ret;
} catch(e) {
if (e.code === 'INVALID_BUFFER_FOR_DECODE') {
return null;
}
throw e;
}
};
return LogicUser;
}
module.exports = createLogicUser;