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