a zip code crypto-currency system good for red ONLY

message.js 888B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. var Message = function() {
  3. this.rsv1 = false;
  4. this.rsv2 = false;
  5. this.rsv3 = false;
  6. this.opcode = null
  7. this.length = 0;
  8. this._chunks = [];
  9. };
  10. var instance = {
  11. read: function() {
  12. if (this.data) return this.data;
  13. this.data = new Buffer(this.length);
  14. var offset = 0;
  15. for (var i = 0, n = this._chunks.length; i < n; i++) {
  16. this._chunks[i].copy(this.data, offset);
  17. offset += this._chunks[i].length;
  18. }
  19. return this.data;
  20. },
  21. pushFrame: function(frame) {
  22. this.rsv1 = this.rsv1 || frame.rsv1;
  23. this.rsv2 = this.rsv2 || frame.rsv2;
  24. this.rsv3 = this.rsv3 || frame.rsv3;
  25. if (this.opcode === null) this.opcode = frame.opcode;
  26. this._chunks.push(frame.payload);
  27. this.length += frame.length;
  28. }
  29. };
  30. for (var key in instance)
  31. Message.prototype[key] = instance[key];
  32. module.exports = Message;