Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mqtt-packet

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mqtt-packet - npm Package Compare versions

Comparing version 6.1.2 to 6.2.0

2

package.json
{
"name": "mqtt-packet",
"version": "6.1.2",
"version": "6.2.0",
"description": "Parse and generate MQTT packets like a breeze",

@@ -5,0 +5,0 @@ "main": "mqtt.js",

@@ -614,3 +614,12 @@ 'use strict'

}
result[name] = this._parseByType(constants.propertiesTypes[name])
if (result[name]) {
if (Array.isArray(result[name])) {
result[name].push(this._parseByType(constants.propertiesTypes[name]))
} else {
result[name] = [result[name]]
result[name].push(this._parseByType(constants.propertiesTypes[name]))
}
} else {
result[name] = this._parseByType(constants.propertiesTypes[name])
}
}

@@ -617,0 +626,0 @@ return result

@@ -330,3 +330,3 @@ mqtt-packet   [![Build Status](https://travis-ci.org/mqttjs/mqtt-packet.png)](https://travis-ci.org/mqttjs/mqtt-packet)

},
subscriptionIdentifier: 120,
subscriptionIdentifier: 120, // can be an Array in message from broker, if message included in few another subscriptions
contentType: 'test'

@@ -333,0 +333,0 @@ }

@@ -912,2 +912,41 @@ 'use strict'

testParseGenerate('publish MQTT5 with multiple same properties', {
cmd: 'publish',
retain: true,
qos: 2,
dup: true,
length: 62,
topic: 'test',
payload: new Buffer('test'),
messageId: 10,
properties: {
payloadFormatIndicator: true,
messageExpiryInterval: 4321,
topicAlias: 100,
responseTopic: 'topic',
correlationData: Buffer.from([1, 2, 3, 4]),
userProperties: {
'test': 'test'
},
subscriptionIdentifier: [120, 121],
contentType: 'test'
}
}, Buffer.from([
61, 62, // Header
0, 4, // Topic length
116, 101, 115, 116, // Topic (test)
0, 10, // Message ID
49, // properties length
1, 1, // payloadFormatIndicator
2, 0, 0, 16, 225, // message expiry interval
35, 0, 100, // topicAlias
8, 0, 5, 116, 111, 112, 105, 99, // response topic
9, 0, 4, 1, 2, 3, 4, // correlationData
38, 0, 4, 116, 101, 115, 116, 0, 4, 116, 101, 115, 116, // userProperties
11, 120, // subscriptionIdentifier
11, 121, // subscriptionIdentifier
3, 0, 4, 116, 101, 115, 116, // content type
116, 101, 115, 116 // Payload (test)
]), { protocolVersion: 5 })
;(function () {

@@ -914,0 +953,0 @@ var buffer = new Buffer(2048)

@@ -862,5 +862,4 @@ 'use strict'

var propertiesLength = 0
function getLengthProperty (name) {
function getLengthProperty (name, value) {
var type = protocol.propertiesTypes[name]
var value = properties[name]
var length = 0

@@ -952,3 +951,11 @@ switch (type) {

for (var propName in properties) {
var propLength = getLengthProperty(propName)
var propLength = 0
var propValue = properties[propName]
if (Array.isArray(propValue)) {
for (var valueIndex = 0; valueIndex < propValue.length; valueIndex++) {
propLength += getLengthProperty(propName, propValue[valueIndex])
}
} else {
propLength = getLengthProperty(propName, propValue)
}
if (!propLength) return false

@@ -987,2 +994,62 @@ propertiesLength += propLength

function writeProperty (stream, propName, value) {
var type = protocol.propertiesTypes[propName]
switch (type) {
case 'byte': {
stream.write(Buffer.from([protocol.properties[propName]]))
stream.write(Buffer.from([+value]))
break
}
case 'int8': {
stream.write(Buffer.from([protocol.properties[propName]]))
stream.write(Buffer.from([value]))
break
}
case 'binary': {
stream.write(Buffer.from([protocol.properties[propName]]))
writeStringOrBuffer(stream, value)
break
}
case 'int16': {
stream.write(Buffer.from([protocol.properties[propName]]))
writeNumber(stream, value)
break
}
case 'int32': {
stream.write(Buffer.from([protocol.properties[propName]]))
write4ByteNumber(stream, value)
break
}
case 'var': {
stream.write(Buffer.from([protocol.properties[propName]]))
writeVarByteInt(stream, value)
break
}
case 'string': {
stream.write(Buffer.from([protocol.properties[propName]]))
writeString(stream, value)
break
}
case 'pair': {
Object.getOwnPropertyNames(value).forEach(function (name) {
var currentValue = value[name]
if (Array.isArray(currentValue)) {
currentValue.forEach(function (value) {
stream.write(Buffer.from([protocol.properties[propName]]))
writeStringPair(stream, name.toString(), value.toString())
})
} else {
stream.write(Buffer.from([protocol.properties[propName]]))
writeStringPair(stream, name.toString(), currentValue.toString())
}
})
break
}
default: {
stream.emit('error', new Error('Invalid property ' + propName + ' value: ' + value))
return false
}
}
}
function writeProperties (stream, properties, propertiesLength) {

@@ -994,58 +1061,8 @@ /* write properties to stream */

var value = properties[propName]
var type = protocol.propertiesTypes[propName]
switch (type) {
case 'byte': {
stream.write(Buffer.from([protocol.properties[propName]]))
stream.write(Buffer.from([+value]))
break
if (Array.isArray(value)) {
for (var valueIndex = 0; valueIndex < value.length; valueIndex++) {
writeProperty(stream, propName, value[valueIndex])
}
case 'int8': {
stream.write(Buffer.from([protocol.properties[propName]]))
stream.write(Buffer.from([value]))
break
}
case 'binary': {
stream.write(Buffer.from([protocol.properties[propName]]))
writeStringOrBuffer(stream, value)
break
}
case 'int16': {
stream.write(Buffer.from([protocol.properties[propName]]))
writeNumber(stream, value)
break
}
case 'int32': {
stream.write(Buffer.from([protocol.properties[propName]]))
write4ByteNumber(stream, value)
break
}
case 'var': {
stream.write(Buffer.from([protocol.properties[propName]]))
writeVarByteInt(stream, value)
break
}
case 'string': {
stream.write(Buffer.from([protocol.properties[propName]]))
writeString(stream, value)
break
}
case 'pair': {
Object.getOwnPropertyNames(value).forEach(function (name) {
var currentValue = value[name]
if (Array.isArray(currentValue)) {
currentValue.forEach(function (value) {
stream.write(Buffer.from([protocol.properties[propName]]))
writeStringPair(stream, name.toString(), value.toString())
})
} else {
stream.write(Buffer.from([protocol.properties[propName]]))
writeStringPair(stream, name.toString(), currentValue.toString())
}
})
break
}
default: {
stream.emit('error', new Error('Invalid property ' + propName))
return false
}
} else {
writeProperty(stream, propName, value)
}

@@ -1052,0 +1069,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc