weechat-protocol.js: prepend _ to private methods names

This commit is contained in:
Philippe Proulx 2013-10-05 15:06:30 -04:00
parent 5a14c1a412
commit f2b44a4e6b

View file

@ -1,15 +1,15 @@
var WeeChatProtocol = function() { var WeeChatProtocol = function() {
this.types = { this._types = {
'chr': this.getChar, 'chr': this._getChar,
'int': this.getInt, 'int': this._getInt,
'str': this.getString, 'str': this._getString,
'inf': this.getInfo, 'inf': this._getInfo,
'hda': this.getHdata, 'hda': this._getHdata,
'ptr': this.getPointer, 'ptr': this._getPointer,
'lon': this.getPointer, 'lon': this._getPointer,
'tim': this.getPointer, 'tim': this._getPointer,
'buf': this.getString, 'buf': this._getString,
'arr': this.getArray 'arr': this._getArray
}; };
}; };
WeeChatProtocol._uia2s = function(uia) { WeeChatProtocol._uia2s = function(uia) {
@ -22,23 +22,23 @@ WeeChatProtocol._uia2s = function(uia) {
return decodeURIComponent(escape(_str.join(""))); return decodeURIComponent(escape(_str.join("")));
}; };
WeeChatProtocol.prototype = { WeeChatProtocol.prototype = {
getInfo: function() { _getInfo: function() {
var info = {}; var info = {};
info.key = this.getString(); info.key = this._getString();
info.value = this.getString(); info.value = this._getString();
return info; return info;
}, },
getHdata: function() { _getHdata: function() {
var self = this; var self = this;
var paths; var paths;
var count; var count;
var objs = []; var objs = [];
var hpath = this.getString(); var hpath = this._getString();
keys = this.getString().split(','); keys = this._getString().split(',');
paths = hpath.split('/'); paths = hpath.split('/');
count = this.getInt(); count = this._getInt();
keys = keys.map(function(key) { keys = keys.map(function(key) {
return key.split(':'); return key.split(':');
@ -48,41 +48,41 @@ WeeChatProtocol.prototype = {
var tmp = {}; var tmp = {};
tmp.pointers = paths.map(function(path) { tmp.pointers = paths.map(function(path) {
return self.getPointer(); return self._getPointer();
}); });
keys.forEach(function(key) { keys.forEach(function(key) {
tmp[key[0]] = self.runType(key[1]); tmp[key[0]] = self._runType(key[1]);
}); });
objs.push(tmp); objs.push(tmp);
}; };
return objs; return objs;
}, },
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 parsed_data = new Uint8Array(pointer);
return WeeChatProtocol._uia2s(parsed_data); return WeeChatProtocol._uia2s(parsed_data);
}, },
getInt: function() { _getInt: function() {
var parsed_data = new Uint8Array(this.getSlice(4)); var parsed_data = new Uint8Array(this._getSlice(4));
return ((parsed_data[0] & 0xff) << 24) | return ((parsed_data[0] & 0xff) << 24) |
((parsed_data[1] & 0xff) << 16) | ((parsed_data[1] & 0xff) << 16) |
((parsed_data[2] & 0xff) << 8) | ((parsed_data[2] & 0xff) << 8) |
(parsed_data[3] & 0xff); (parsed_data[3] & 0xff);
}, },
getChar: function() { _getChar: function() {
var parsed_data = new Uint8Array(this.getSlice(1)); var parsed_data = new Uint8Array(this._getSlice(1));
return parsed_data[0]; return parsed_data[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 parsed_data = new Uint8Array(s);
return WeeChatProtocol._uia2s(parsed_data); return WeeChatProtocol._uia2s(parsed_data);
@ -90,59 +90,59 @@ WeeChatProtocol.prototype = {
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);
return slice; return slice;
}, },
getType: function() { _getType: function() {
var t = this.getSlice(3); var t = this._getSlice(3);
return WeeChatProtocol._uia2s(new Uint8Array(t)); return WeeChatProtocol._uia2s(new Uint8Array(t));
}, },
runType: function(type) { _runType: function(type) {
var cb = this.types[type]; var cb = this._types[type];
var boundCb = cb.bind(this); var boundCb = cb.bind(this);
return boundCb(); return boundCb();
}, },
getHeader: function() { _getHeader: function() {
var len = this.getInt(); var len = this._getInt();
var comp = this.getChar(); var comp = this._getChar();
return { return {
length: len, length: len,
compression: comp, compression: comp,
}; };
}, },
getId: function() { _getId: function() {
return this.getString(); return this._getString();
}, },
getObject: function() { _getObject: function() {
var self = this; var self = this;
var type = this.getType(); var type = this._getType();
if (type) { if (type) {
return object = { return object = {
type: type, type: type,
content: self.runType(type), content: self._runType(type),
} }
} }
}, },
parse: function(data) { parse: function(data) {
var self = this; var self = this;
this.setData(data); this._setData(data);
var header = this.getHeader(); var header = this._getHeader();
var id = this.getId(); var id = this._getId();
var objects = []; var objects = [];
var object = this.getObject(); var object = this._getObject();
while (object) { while (object) {
objects.push(object); objects.push(object);
object = self.getObject(); object = self._getObject();
} }
return { return {
@ -151,21 +151,21 @@ WeeChatProtocol.prototype = {
objects: objects, objects: objects,
}; };
}, },
setData: function (data) { _setData: function (data) {
this.data = data; this.data = data;
}, },
getArray: function() { _getArray: function() {
var self = this; var self = this;
var type; var type;
var count; var count;
var values; var values;
type = this.getType(); type = this._getType();
count = this.getInt(); count = this._getInt();
values = []; values = [];
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
values.push(self.runType(type)); values.push(self._runType(type));
}; };
return values; return values;