weechat-protocol.js: uniformize code

This commit is contained in:
Philippe Proulx 2013-10-05 15:10:57 -04:00
parent 7011f8f6b9
commit c12f56c614

View file

@ -72,37 +72,37 @@ WeeChatProtocol.prototype = {
_getPointer: function() { _getPointer: function() {
var l = this._getChar(); var l = this._getChar();
var pointer = this._getSlice(l) var pointer = this._getSlice(l)
var parsed_data = new Uint8Array(pointer); var parsedData = new Uint8Array(pointer);
return WeeChatProtocol._uia2s(parsed_data); return WeeChatProtocol._uia2s(parsedData);
}, },
_getInt: function() { _getInt: function() {
var parsed_data = new Uint8Array(this._getSlice(4)); var parsedData = new Uint8Array(this._getSlice(4));
return ((parsed_data[0] & 0xff) << 24) | return ((parsedData[0] & 0xff) << 24) |
((parsed_data[1] & 0xff) << 16) | ((parsedData[1] & 0xff) << 16) |
((parsed_data[2] & 0xff) << 8) | ((parsedData[2] & 0xff) << 8) |
(parsed_data[3] & 0xff); (parsedData[3] & 0xff);
}, },
_getChar: function() { _getChar: function() {
var parsed_data = new Uint8Array(this._getSlice(1)); var parsedData = new Uint8Array(this._getSlice(1));
return parsed_data[0]; return parsedData[0];
}, },
_getString: function() { _getString: function() {
var l = this._getInt(); var l = this._getInt();
if (l > 0) { if (l > 0) {
var s = this._getSlice(l); var s = this._getSlice(l);
var parsed_data = new Uint8Array(s); var parsedData = new Uint8Array(s);
return WeeChatProtocol._uia2s(parsed_data); return WeeChatProtocol._uia2s(parsedData);
} }
return ""; return "";
}, },
_getSlice: function(length) { _getSlice: function(length) {
var slice = this.data.slice(0,length); var slice = this.data.slice(0, length);
this.data = this.data.slice(length); this.data = this.data.slice(length);
@ -125,10 +125,10 @@ WeeChatProtocol.prototype = {
var type = this._getType(); var type = this._getType();
if (type) { if (type) {
return object = { return {
type: type, type: type,
content: self._runType(type), content: self._runType(type),
} };
} }
}, },
_getArray: function() { _getArray: function() {