Implements principal protocol

Passes test: it properly interprets all data given by weechat's
test command.
This commit is contained in:
David Cormier 2013-07-20 14:23:09 -04:00
parent f5869438b7
commit 4bebd3af79
2 changed files with 89 additions and 24 deletions

View file

@ -7,28 +7,50 @@ var Protocol = function() {
return info; return info;
}; };
var types = { var getHdata = function() {
chr: getChar, var paths;
"int": getInt, var count;
"str": getString, var objs = [];
"inf": getInfo, var hpath = getString();
};
//TODO: IMPLEMENT THIS STUFF
// chr: this.getChar,
// 'int': getInt, keys = getString().split(',');
// hacks paths = hpath.split('/');
// lon: getPointer, count = getInt();
// str: getString,
// buf: getBuffer, keys = keys.map(function(key) {
// ptr: getPointer, return key.split(':');
// hacks });
// tim: getPointer, var i;
// htb: getHashtable, console.log("Keys: ", keys);
// hda: getHdata, console.log("Paths: ", paths);
// inf: Protocol.getInfo, console.log("Count: ", count);
// inl: getInfolist, for (i = 0; i < count; i++) {
// arr: array var tmp = {};
// },
tmp.pointers = paths.map(function(path) {
return getPointer();
});
console.log("Pointers: ", tmp.pointers);
keys.forEach(function(key) {
tmp[key[0]] = runType(key[1]);
});
objs.push(tmp);
};
return objs;
};
function getPointer() {
var l = getChar();
console.log("Length: ", l);
var pointer = getSlice(l)
var parsed_data = new Uint8Array(pointer);
return _uiatos(parsed_data);
};
var _uiatos =function(uia) { var _uiatos =function(uia) {
var _str = []; var _str = [];
@ -48,7 +70,7 @@ var Protocol = function() {
var getChar = function() { var getChar = function() {
var parsed_data = new Uint8Array(getSlice(1)); var parsed_data = new Uint8Array(getSlice(1));
return parsed_data[0]; return parsed_data[0];
} };
var getString = function() { var getString = function() {
var l = getInt(); var l = getInt();
@ -100,6 +122,7 @@ var Protocol = function() {
} }
self.parse = function() { self.parse = function() {
console.log(new Uint8Array(self.data));
var header = getHeader(); var header = getHeader();
var id = getId(); var id = getId();
var objects = []; var objects = [];
@ -108,6 +131,8 @@ var Protocol = function() {
objects.push(object); objects.push(object);
object = getObject(); object = getObject();
} }
console.log("Received message");
console.log(header, id, objects);
return { return {
header: header, header: header,
id: id, id: id,
@ -118,4 +143,44 @@ var Protocol = function() {
self.setData = function (data) { self.setData = function (data) {
self.data = data; self.data = data;
}; };
function array() {
var type;
var count;
var values;
type = getType();
count = getInt();
values = [];
var i;
for (i = 0; i < count; i++) {
values.push(runType(type));
};
return values;
}
var types = {
chr: getChar,
"int": getInt,
str: getString,
inf: getInfo,
hda: getHdata,
ptr: getPointer,
lon: getPointer,
tim: getPointer,
buf: getString,
arr: array
};
//TODO: IMPLEMENT THIS STUFF
// chr: this.getChar,
// 'int': getInt,
// hacks
// hacks
// htb: getHashtable,
// inf: Protocol.getInfo,
// inl: getInfolist,
// },
} }

View file

@ -18,7 +18,7 @@ weechat.factory('connection', ['$rootScope', function($scope) {
websocket.onopen = function (evt) { websocket.onopen = function (evt) {
if (proto == "weechat") { if (proto == "weechat") {
//doSend("init compression=off\nversion\n"); doSend("init compression=off\nversion\n");
} else { } else {
doSend("PASS " + password + "\r\nNICK test\r\nUSER test 0 * :test\r\n"); doSend("PASS " + password + "\r\nNICK test\r\nUSER test 0 * :test\r\n");
} }