{"name":"mqtt-packet","version":"6.3.2","keywords":["MQTT","packet","parse","publish","subscribe","pubsub"],"license":"MIT","_id":"mqtt-packet@6.3.2","maintainers":[{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"wuhkuh","email":"contact@wuhkuh.com"}],"contributors":[{"url":"https://github.com/mcollina","name":"Matteo Collina","email":"matteo.collina@gmail.com"},{"name":"Adam Rudd","email":"damvrr@gmail.com"},{"url":"https://github.com/psorowka","name":"Peter Sorowka"},{"url":"https://github.com/wuhkuh","name":"Wouter Klijn","email":"contact@wuhkuh.com"},{"url":"https://github.com/scarry1992","name":"Siarhei Buntsevich"}],"homepage":"https://github.com/mqttjs/mqtt-packet","bugs":{"url":"https://github.com/mqttjs/mqtt-packet/issues"},"dist":{"shasum":"a737734a9a64e8cffbad7ad9e116d35b912f2e00","tarball":"http://registry-npm.ywwl.com/mqtt-packet/download/mqtt-packet-6.3.2.tgz","fileCount":19,"integrity":"sha512-i56+2kN6F57KInGtjjfUXSl4xG8u/zOvfaXFLKFAbBXzWkXOmwcmjaSCBPayf2IQCkQU0+h+S2DizCo3CF6gQA==","signatures":[{"sig":"MEQCIBR49ICGqJeoyE6lLVMAs2DgMLV5+TeTI+HahyABwfcKAiAgbyGcPQXobup1ry9FLG7DifwVglPNVLzKBJjUKdxldg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":131305,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeXmWwCRA9TVsSAnZWagAAMdQP/2i9T/JMnLIGTRAQBZ0v\nLwTXOkxLPdy8NWHS5dJKvWUnvAU4M0zH9SGwSBkRbKT8PZyrdFLxNakdiODV\nFBdeUJQFCJWq4vZkE3Ut8RqwMDT4XZO2PxG/EtRXTZGJ/TTB1zchL0oKWvLZ\nzRigD3yPFhwP0VeIB+qg0kI0/mmJQgvjo2ssrsLFZctrTel2FjIMd8lrnOTJ\nHSUnah/3jBCJIYkOAhOn2bNnOhQjsKDzUilisYNuE4PzVGb0NKTYKzB2MdJr\nv87HbdR8q9q2Y5eJhTPq1WYnok481tRhawNeuuMHDJcsW3K6zG2J5qhqoTXc\nArt5OFmkbs8SBl8dOPwgA73Ckdaf/5lh0ZPbMb+PODP0LEocI40d/29WPn+W\nNofRvmepkzsI0ZuvUNuwbrhM7Jaj6WRuYM4WM2RI/0HBFKhtaXhukEhLKawE\n/CUYdh8SI3guFV9YJv4D+AoabpEZgzbdwxIwuABNujo0Y+QjzQp6xafdSBaa\nnFoUGz+vt/jAd9OHwqr3/KvxrH4NFM9YxrZ+lG2fI+D39scHoltyfH5iHZ0K\n1LihmKNc9qglgxzrsnfwOf9C/h3LltI13OhnAL3lkL9TLnhECOtyOD300lz+\nMpfR0ps/XFhuZB18OuelBb1B8kMTcOy9sBidTrrdPN+6JZgo4027bfTTmQmn\n3uOE\r\n=kdbp\r\n-----END PGP SIGNATURE-----\r\n","size":24795,"noattachment":false,"key":"/mqtt-packet/-/mqtt-packet-6.3.2.tgz"},"main":"mqtt.js","types":"types/index.d.ts","gitHead":"324fd31ba3d375ac8ad335cd108737c4d77f9379","scripts":{"ci":"tape test.js && node testRandom && standard","test":"tape test.js | tap-spec && standard"},"_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"pre-commit":"test","repository":{"url":"git+https://github.com/mqttjs/mqtt-packet.git","type":"git"},"_npmVersion":"6.13.4","description":"Parse and generate MQTT packets like a breeze","directories":{},"_nodeVersion":"12.16.1","dependencies":{"bl":"^1.2.2","debug":"^4.1.1","inherits":"^2.0.3","safe-buffer":"^5.1.2","process-nextick-args":"^2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"tape":"^4.10.1","dev-null":"^0.1.1","standard":"^10.0.2","tap-spec":"^4.1.2","pre-commit":"^1.2.2","readable-stream":"^2.3.6"},"_npmOperationalInternal":{"tmp":"tmp/mqtt-packet_6.3.2_1583244719969_0.8070211454379141","host":"s3://npm-registry-packages"},"readme":"mqtt-packet\n===========\n\nEncode and Decode MQTT 3.1.1, 5.0 packets the node way.\n\n[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\n  * <a href=\"#installation\">Installation</a>\n  * <a href=\"#examples\">Examples</a>\n  * <a href=\"#packets\">Packets</a>\n  * <a href=\"#api\">API</a>\n  * <a href=\"#contributing\">Contributing</a>\n  * <a href=\"#license\">License &amp; copyright</a>\n\nThis library is tested with node v6, v8, v10, v12 and v14. The last version to support\nolder versions of node was mqtt-packet@4.1.2.\n\nInstallation\n------------\n\n```bash\nnpm install mqtt-packet --save\n```\n\nExamples\n--------\n\n### Generating\n\n```js\nconst mqtt = require('mqtt-packet');\nconst object = {\n  cmd: 'publish',\n  retain: false,\n  qos: 0,\n  dup: false,\n  length: 10,\n  topic: 'test',\n  payload: 'test' // Can also be a Buffer\n};\nconst opts = { protocolVersion: 4 }; // default is 4. Usually, opts is a connect packet\n\nconsole.log(mqtt.generate(object))\n// Prints:\n//\n// <Buffer 30 0a 00 04 74 65 73 74 74 65 73 74>\n//\n// Which is the same as:\n//\n// Buffer.from([\n//   48, 10, // Header (publish)\n//   0, 4, // Topic length\n//   116, 101, 115, 116, // Topic (test)\n//   116, 101, 115, 116 // Payload (test)\n// ])\n```\n\n### Parsing\n\n```js\nconst mqtt = require('mqtt-packet');\nconst opts = { protocolVersion: 4 }; // default is 4. Usually, opts is a connect packet\nconst parser = mqtt.parser(opts);\n\n// Synchronously emits all the parsed packets\nparser.on('packet', packet => {\n  console.log(packet)\n  // Prints:\n  //\n  // {\n  //   cmd: 'publish',\n  //   retain: false,\n  //   qos: 0,\n  //   dup: false,\n  //   length: 10,\n  //   topic: 'test',\n  //   payload: <Buffer 74 65 73 74>\n  // }\n})\n\nparser.parse(Buffer.from([\n  48, 10, // Header (publish)\n  0, 4, // Topic length\n  116, 101, 115, 116, // Topic (test)\n  116, 101, 115, 116 // Payload (test)\n]))\n// Returns the number of bytes left in the parser\n```\n\nAPI\n---\n\n  * <a href=\"#generate\"><code>mqtt#<b>generate()</b></code></a>\n  * <a href=\"#writeToStream\"><code>mqtt#<b>writeToStream()</b></code></a>\n  * <a href=\"#parser\"><code>mqtt#<b>parser()</b></code></a>\n\n<a name=\"generate\">\n\n### mqtt.generate(object, [opts])\n\nGenerates a `Buffer` containing an MQTT packet.\nThe object must be one of the ones specified by the [packets](#packets)\nsection. Throws an `Error` if a packet cannot be generated.\n\n<a name=\"writeToStream\">\n\n### mqtt.writeToStream(object, stream, [opts])\n\nWrites the mqtt packet defined by `object` to the given stream.\nThe object must be one of the ones specified by the [packets](#packets)\nsection. Emits an `Error` on the stream if a packet cannot be generated.\nOn node >= 0.12, this function automatically calls `cork()` on your stream,\nand then it calls `uncork()` on the next tick.\nBy default cache for number buffers is enabled.\nIt creates a list of buffers for faster write. To disable cache set `mqtt.writeToStream.cacheNumbers = false`.\nShould be set before any `writeToStream` calls.\n\n<a name=\"parser\">\n\n### mqtt.parser([opts])\n\nReturns a new `Parser` object. `Parser` inherits from `EventEmitter` and\nwill emit:\n\n  * `packet`, when a new packet is parsed, according to\n    [packets](#packets)\n  * `error`, if an error happens\n\n<a name=\"parse\">\n\n#### Parser.parse(buffer)\n\nParses a given `Buffer` and emits synchronously all the MQTT packets that\nare included. Returns the number of bytes left to parse.\n\nIf an error happens, an `error` event will be emitted, but no `packet` events\nwill be emitted after that. Calling `parse()` again clears the error and\nprevious buffer, as if you created a new `Parser`.\n\nPackets\n-------\n\nThis section describes the format of all packets emitted by the `Parser`\nand that you can input to `generate`.\n\n### Connect\n\n```js\n{\n  cmd: 'connect',\n  protocolId: 'MQTT', // Or 'MQIsdp' in MQTT 3.1 and 5.0\n  protocolVersion: 4, // Or 3 in MQTT 3.1, or 5 in MQTT 5.0\n  clean: true, // Can also be false\n  clientId: 'my-device',\n  keepalive: 0, // Seconds which can be any positive number, with 0 as the default setting\n  username: 'matteo',\n  password: Buffer.from('collina'), // Passwords are buffers\n  will: {\n    topic: 'mydevice/status',\n    payload: Buffer.from('dead'), // Payloads are buffers\n    properties: { // MQTT 5.0\n      willDelayInterval: 1234,\n      payloadFormatIndicator: false,\n      messageExpiryInterval: 4321,\n      contentType: 'test',\n      responseTopic: 'topic',\n      correlationData: Buffer.from([1, 2, 3, 4]),\n      userProperties: {\n        'test': 'test'\n      }\n    }\n  },\n  properties: { // MQTT 5.0 properties\n      sessionExpiryInterval: 1234,\n      receiveMaximum: 432,\n      maximumPacketSize: 100,\n      topicAliasMaximum: 456,\n      requestResponseInformation: true,\n      requestProblemInformation: true,\n      userProperties: {\n        'test': 'test'\n      },\n      authenticationMethod: 'test',\n      authenticationData: Buffer.from([1, 2, 3, 4])\n  }\n}\n```\n\nIf `protocolVersion` is 3, `clientId` is mandatory and `generate` will throw if\nmissing.\n\nIf `password` or `will.payload` are passed as strings, they will\nautomatically be converted into a `Buffer`.\n\n### Connack\n\n```js\n{\n  cmd: 'connack',\n  returnCode: 0, // Or whatever else you see fit MQTT < 5.0\n  sessionPresent: false, // Can also be true.\n  reasonCode: 0, // reason code MQTT 5.0\n  properties: { // MQTT 5.0 properties\n      sessionExpiryInterval: 1234,\n      receiveMaximum: 432,\n      maximumQoS: 1,\n      retainAvailable: true,\n      maximumPacketSize: 100,\n      assignedClientIdentifier: 'test',\n      topicAliasMaximum: 456,\n      reasonString: 'test',\n      userProperties: {\n        'test': 'test'\n      },\n      wildcardSubscriptionAvailable: true,\n      subscriptionIdentifiersAvailable: true,\n      sharedSubscriptionAvailable: false,\n      serverKeepAlive: 1234,\n      responseInformation: 'test',\n      serverReference: 'test',\n      authenticationMethod: 'test',\n      authenticationData: Buffer.from([1, 2, 3, 4])\n  }\n}\n```\n\nThe only mandatory argument is `returnCode`, as `generate` will throw if\nmissing.\n\n### Subscribe\n\n```js\n{\n  cmd: 'subscribe',\n  messageId: 42,\n  properties: { // MQTT 5.0 properties\n    subscriptionIdentifier: 145,\n    userProperties: {\n      test: 'test'\n    }\n  }\n  subscriptions: [{\n    topic: 'test',\n    qos: 0,\n    nl: false, // no Local MQTT 5.0 flag\n    rap: true, // Retain as Published MQTT 5.0 flag\n    rh: 1 // Retain Handling MQTT 5.0\n  }]\n}\n```\n\nAll properties are mandatory.\n\n### Suback\n\n```js\n{\n  cmd: 'suback',\n  messageId: 42,\n  properties: { // MQTT 5.0 properties\n    reasonString: 'test',\n    userProperties: {\n      'test': 'test'\n    }\n  }\n  granted: [0, 1, 2, 128]\n}\n```\n\nAll the granted qos __must__ be < 256, as they are encoded as UInt8.\nAll properties are mandatory.\n\n### Unsubscribe\n\n```js\n{\n  cmd: 'unsubscribe',\n  messageId: 42,\n  properties: { // MQTT 5.0 properties\n    userProperties: {\n      'test': 'test'\n    }\n  }\n  unsubscriptions: [\n    'test',\n    'a/topic'\n  ]\n}\n```\n\nAll properties are mandatory.\n\n### Unsuback\n\n```js\n{\n  cmd: 'unsuback',\n  messageId: 42,\n  properties: { // MQTT 5.0 properties\n    reasonString: 'test',\n    userProperties: {\n      'test': 'test'\n    }\n  }\n}\n```\n\nAll properties are mandatory.\n\n### Publish\n\n```js\n{\n  cmd: 'publish',\n  messageId: 42,\n  qos: 2,\n  dup: false,\n  topic: 'test',\n  payload: Buffer.from('test'),\n  retain: false,\n  properties: { // optional properties MQTT 5.0\n      payloadFormatIndicator: true,\n      messageExpiryInterval: 4321,\n      topicAlias: 100,\n      responseTopic: 'topic',\n      correlationData: Buffer.from([1, 2, 3, 4]),\n      userProperties: {\n        'test': 'test'\n      },\n      subscriptionIdentifier: 120, // can be an Array in message from broker, if message included in few another subscriptions\n      contentType: 'test'\n   }\n}\n```\n\nOnly the `topic` property is mandatory.\nBoth `topic` and `payload` can be `Buffer` objects instead of strings.\n`messageId` is mandatory for `qos > 0`.\n\n### Puback\n\n```js\n{\n  cmd: 'puback',\n  messageId: 42,\n  reasonCode: 16, // only for MQTT 5.0\n  properties: { // MQTT 5.0 properties\n      reasonString: 'test',\n      userProperties: {\n        'test': 'test'\n      }\n  }\n}\n```\n\nThe only mandatory property is `messageId`, as `generate` will throw if\nmissing.\n\n### Pubrec\n\n```js\n{\n  cmd: 'pubrec',\n  messageId: 42,\n  reasonCode: 16, // only for MQTT 5.0\n  properties: { // properties MQTT 5.0\n    reasonString: 'test',\n    userProperties: {\n      'test': 'test'\n    }\n  }\n}\n```\n\nThe only mandatory property is `messageId`, as `generate` will throw if\nmissing.\n\n### Pubrel\n\n```js\n{\n  cmd: 'pubrel',\n  messageId: 42,\n  reasonCode: 16, // only for MQTT 5.0\n  properties: { // properties MQTT 5.0\n     reasonString: 'test',\n     userProperties: {\n       'test': 'test'\n     }\n  }\n}\n```\n\nThe only mandatory property is `messageId`, as `generate` will throw if\nmissing.\n\n### Pubcomp\n\n```js\n{\n  cmd: 'pubcomp',\n  messageId: 42,\n  reasonCode: 16, // only for MQTT 5.0\n  properties: { // properties MQTT 5.0\n    reasonString: 'test',\n    userProperties: {\n       'test': 'test'\n    }\n  }\n}\n```\n\nThe only mandatory property is `messageId`, as `generate` will throw if\nmissing.\n\n### Pingreq\n\n```js\n{\n  cmd: 'pingreq'\n}\n```\n\n### Pingresp\n\n```js\n{\n  cmd: 'pingresp'\n}\n```\n\n### Disconnect\n\n```js\n{\n  cmd: 'disconnect',\n  reasonCode: 0, // MQTT 5.0 code\n  properties: { // properties MQTT 5.0\n     sessionExpiryInterval: 145,\n     reasonString: 'test',\n     userProperties: {\n       'test': 'test'\n     },\n     serverReference: 'test'\n  }\n}\n```\n\n### Auth\n\n```js\n{\n  cmd: 'auth',\n  reasonCode: 0, // MQTT 5.0 code\n  properties: { // properties MQTT 5.0\n     authenticationMethod: 'test',\n     authenticationData: Buffer.from([0, 1, 2, 3]),\n     reasonString: 'test',\n     userProperties: {\n       'test': 'test'\n     }\n  }\n}\n```\n\n<a name=\"contributing\"></a>\n\nContributing\n------------\n\nmqtt-packet is an **OPEN Open Source Project**. This means that:\n\n> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.\n\nSee the [CONTRIBUTING.md](https://github.com/mqttjs/mqtt-packet/blob/master/CONTRIBUTING.md) file for more details.\n\n### Contributors\n\nmqtt-packet is only possible due to the excellent work of the following contributors:\n\n<table><tbody>\n<tr><th align=\"left\">Matteo Collina</th><td><a href=\"https://github.com/mcollina\">GitHub/mcollina</a></td><td><a href=\"http://twitter.com/matteocollina\">Twitter/@matteocollina</a></td></tr>\n<tr><th align=\"left\">Adam Rudd</th><td><a href=\"https://github.com/adamvr\">GitHub/adamvr</a></td><td><a href=\"http://twitter.com/adam_vr\">Twitter/@adam_vr</a></td></tr>\n<tr><th align=\"left\">Peter Sorowka</th><td><a href=\"https://github.com/psorowka\">GitHub/psorowka</a></td><td><a href=\"http://twitter.com/psorowka\">Twitter/@psorowka</a></td></tr>\n<tr><th align=\"left\">Siarhei Buntsevich</th><td><a href=\"https://github.com/scarry1992\">GitHub/scarry1992</a></td></tr>\n</tbody></table>\n\nLicense\n-------\n\nMIT\n","publish_time":1583244720196,"_cnpm_publish_time":1583244720196,"dist-tags":{"latest":"9.0.2","legacy-v4":"4.1.3","next":"8.0.0","v3-stable":"3.5.1"}}