weechat-protocol.js: add time parsing and factor "number as string" code
This commit is contained in:
parent
fef3e7542a
commit
de163d6bc9
1 changed files with 14 additions and 7 deletions
|
@ -6,8 +6,8 @@ var WeeChatProtocol = function() {
|
||||||
'inf': this._getInfo,
|
'inf': this._getInfo,
|
||||||
'hda': this._getHdata,
|
'hda': this._getHdata,
|
||||||
'ptr': this._getPointer,
|
'ptr': this._getPointer,
|
||||||
'lon': this._getPointer,
|
'lon': this._getStrNumber,
|
||||||
'tim': this._getPointer,
|
'tim': this._getTime,
|
||||||
'buf': this._getString,
|
'buf': this._getString,
|
||||||
'arr': this._getArray
|
'arr': this._getArray
|
||||||
};
|
};
|
||||||
|
@ -33,6 +33,12 @@ WeeChatProtocol.prototype = {
|
||||||
|
|
||||||
return boundCb();
|
return boundCb();
|
||||||
},
|
},
|
||||||
|
_getStrNumber: function() {
|
||||||
|
var len = new Uint8Array(this._getSlice(1))[0];
|
||||||
|
var str = this._getSlice(len);
|
||||||
|
|
||||||
|
return WeeChatProtocol._uia2s(new Uint8Array(str));
|
||||||
|
},
|
||||||
_getInfo: function() {
|
_getInfo: function() {
|
||||||
var info = {};
|
var info = {};
|
||||||
info.key = this._getString();
|
info.key = this._getString();
|
||||||
|
@ -70,11 +76,12 @@ WeeChatProtocol.prototype = {
|
||||||
return objs;
|
return objs;
|
||||||
},
|
},
|
||||||
_getPointer: function() {
|
_getPointer: function() {
|
||||||
var l = this._getChar();
|
return this._getStrNumber();
|
||||||
var pointer = this._getSlice(l)
|
},
|
||||||
var parsedData = new Uint8Array(pointer);
|
_getTime: function() {
|
||||||
|
var str = this._getStrNumber();
|
||||||
|
|
||||||
return WeeChatProtocol._uia2s(parsedData);
|
return new Date(parseInt(str));
|
||||||
},
|
},
|
||||||
_getInt: function() {
|
_getInt: function() {
|
||||||
var parsedData = new Uint8Array(this._getSlice(4));
|
var parsedData = new Uint8Array(this._getSlice(4));
|
||||||
|
|
Loading…
Reference in a new issue