From de163d6bc9eda523aedf85454389fda1cc027715 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Sat, 5 Oct 2013 15:53:40 -0400 Subject: [PATCH] weechat-protocol.js: add time parsing and factor "number as string" code --- js/weechat-protocol.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/js/weechat-protocol.js b/js/weechat-protocol.js index 90c2e23..8bbf159 100644 --- a/js/weechat-protocol.js +++ b/js/weechat-protocol.js @@ -6,8 +6,8 @@ var WeeChatProtocol = function() { 'inf': this._getInfo, 'hda': this._getHdata, 'ptr': this._getPointer, - 'lon': this._getPointer, - 'tim': this._getPointer, + 'lon': this._getStrNumber, + 'tim': this._getTime, 'buf': this._getString, 'arr': this._getArray }; @@ -33,6 +33,12 @@ WeeChatProtocol.prototype = { 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() { var info = {}; info.key = this._getString(); @@ -70,11 +76,12 @@ WeeChatProtocol.prototype = { return objs; }, _getPointer: function() { - var l = this._getChar(); - var pointer = this._getSlice(l) - var parsedData = new Uint8Array(pointer); - - return WeeChatProtocol._uia2s(parsedData); + return this._getStrNumber(); + }, + _getTime: function() { + var str = this._getStrNumber(); + + return new Date(parseInt(str)); }, _getInt: function() { var parsedData = new Uint8Array(this._getSlice(4));