diff --git a/packet.js b/packet.js new file mode 100644 index 0000000..cf2cf29 --- /dev/null +++ b/packet.js @@ -0,0 +1,12 @@ + +function Packet() { + this.cmd = null + this.retain = false + this.qos = 0 + this.dup = false + this.length = -1 + this.topic = null + this.payload = null +} + +module.exports = Packet diff --git a/parser.js b/parser.js index 4431245..626000c 100644 --- a/parser.js +++ b/parser.js @@ -2,6 +2,7 @@ var bl = require('bl') , inherits = require('inherits') , EE = require('events').EventEmitter + , Packet = require('./packet') , constants = require('./constants') function Parser() { @@ -29,9 +30,7 @@ Parser.prototype._newPacket = function () { this.emit('packet', this.packet) } - this.packet = { - length: -1 - } + this.packet = new Packet() return true } diff --git a/test.js b/test.js index 3a5e29a..d2e03f2 100644 --- a/test.js +++ b/test.js @@ -11,6 +11,10 @@ function testParseGenerate(name, object, buffer, opts) { , fixture = buffer parser.on('packet', function(packet) { + if (packet.cmd !== 'publish') { + delete packet.topic + delete packet.payload + } t.deepEqual(packet, expected, 'expected packet') }) @@ -30,6 +34,10 @@ function testParseGenerate(name, object, buffer, opts) { , fixture = mqtt.generate(object) parser.on('packet', function(packet) { + if (packet.cmd !== 'publish') { + delete packet.topic + delete packet.payload + } t.deepEqual(packet, expected, 'expected packet') })