StatisticsPacket.js 544 B

1234567891011121314151617181920
  1. module.exports = StatisticsPacket;
  2. function StatisticsPacket() {
  3. this.message = undefined;
  4. }
  5. StatisticsPacket.prototype.parse = function(parser) {
  6. this.message = parser.parsePacketTerminatedString();
  7. var items = this.message.split(/\s\s/);
  8. for (var i = 0; i < items.length; i++) {
  9. var m = items[i].match(/^(.+)\:\s+(.+)$/);
  10. if (m !== null) {
  11. this[m[1].toLowerCase().replace(/\s/g, '_')] = Number(m[2]);
  12. }
  13. }
  14. };
  15. StatisticsPacket.prototype.write = function(writer) {
  16. writer.writeString(this.message);
  17. };