Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function MessageComposer(id) {
- this.id = id;
- this.msg = [base64Encoding.encode(id)];
- this.pushString = function(str) {
- this.msg.push(base64Encoding.encode(str.length), str);
- };
- this.pushInteger = function(i) {
- this.msg.push(wireEncoding.encode(i));
- };
- this.pushBoolean = function(b) {
- this.msg.push(b ? "I" : "H");
- };
- this.getResult = function() {
- return this.msg.join("");
- };
- return this;
- }
- function MessageEvent(msg) {
- this.msg = msg;
- this.pointer = 2;
- this.id = base64Encoding.decode(msg.substr(0, 2));
- this.remainingLength = function() {
- return this.msg.length - this.pointer;
- };
- this.readString = function() {
- length = base64Encoding.decode(this.msg.substr(this.pointer, 2));
- this.pointer += 2;
- if (length > this.remainingLength()) length = this.remainingLength();
- data = this.msg.substr(this.pointer, length);
- this.pointer += length;
- return data;
- };
- this.readBoolean = function() {
- xint = wireEncoding.decode(this.msg.substr(this.pointer, 1), 0);
- this.pointer++;
- return xint == 1;
- };
- this.readInteger = function() {
- if (this.remainingLength() < 1) return 0;
- length = 6;
- if (length > this.remainingLength()) length = this.remainingLength();
- data = this.msg.substr(this.pointer, length);
- int_e = wireEncoding.decode(data);
- this.pointer += int_e[0];
- return int_e[1];
- };
- return this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement