Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.38 KB | None | 0 0
  1. function MessageComposer(id) {
  2.     this.id  = id;
  3.     this.msg = [base64Encoding.encode(id)];
  4.     this.pushString = function(str) {
  5.         this.msg.push(base64Encoding.encode(str.length), str);
  6.     };
  7.     this.pushInteger = function(i) {
  8.         this.msg.push(wireEncoding.encode(i));
  9.     };
  10.     this.pushBoolean = function(b) {
  11.         this.msg.push(b ? "I" : "H");
  12.     };
  13.     this.getResult = function() {
  14.         return this.msg.join("");
  15.     };
  16.     return this;
  17. }
  18. function MessageEvent(msg) {
  19.     this.msg        = msg;
  20.     this.pointer    = 2;
  21.     this.id   = base64Encoding.decode(msg.substr(0, 2));
  22.     this.remainingLength = function() {
  23.         return this.msg.length - this.pointer;
  24.     };
  25.     this.readString = function() {
  26.         length = base64Encoding.decode(this.msg.substr(this.pointer, 2));
  27.         this.pointer += 2;
  28.         if (length > this.remainingLength()) length = this.remainingLength();
  29.         data = this.msg.substr(this.pointer, length);
  30.         this.pointer += length;
  31.         return data;
  32.     };
  33.     this.readBoolean = function() {
  34.         xint = wireEncoding.decode(this.msg.substr(this.pointer, 1), 0);
  35.         this.pointer++;
  36.         return xint == 1;
  37.     };
  38.     this.readInteger = function() {
  39.         if (this.remainingLength() < 1) return 0;
  40.         length = 6;
  41.         if (length > this.remainingLength()) length = this.remainingLength();
  42.         data = this.msg.substr(this.pointer, length);
  43.         int_e = wireEncoding.decode(data);
  44.         this.pointer += int_e[0];
  45.         return int_e[1];
  46.     };
  47.     return this;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement