/usr/lib/nodejs/mqtt-packet/constants.js is in node-mqtt-packet 5.4.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | 'use strict'
var Buffer = require('safe-buffer').Buffer
/* Protocol - protocol constants */
var protocol = module.exports
/* Command code => mnemonic */
protocol.types = {
0: 'reserved',
1: 'connect',
2: 'connack',
3: 'publish',
4: 'puback',
5: 'pubrec',
6: 'pubrel',
7: 'pubcomp',
8: 'subscribe',
9: 'suback',
10: 'unsubscribe',
11: 'unsuback',
12: 'pingreq',
13: 'pingresp',
14: 'disconnect',
15: 'reserved'
}
/* Mnemonic => Command code */
protocol.codes = {}
for (var k in protocol.types) {
var v = protocol.types[k]
protocol.codes[v] = k
}
/* Header */
protocol.CMD_SHIFT = 4
protocol.CMD_MASK = 0xF0
protocol.DUP_MASK = 0x08
protocol.QOS_MASK = 0x03
protocol.QOS_SHIFT = 1
protocol.RETAIN_MASK = 0x01
/* Length */
protocol.LENGTH_MASK = 0x7F
protocol.LENGTH_FIN_MASK = 0x80
/* Connack */
protocol.SESSIONPRESENT_MASK = 0x01
protocol.SESSIONPRESENT_HEADER = Buffer.from([protocol.SESSIONPRESENT_MASK])
protocol.CONNACK_HEADER = Buffer.from([protocol.codes['connack'] << protocol.CMD_SHIFT])
/* Connect */
protocol.USERNAME_MASK = 0x80
protocol.PASSWORD_MASK = 0x40
protocol.WILL_RETAIN_MASK = 0x20
protocol.WILL_QOS_MASK = 0x18
protocol.WILL_QOS_SHIFT = 3
protocol.WILL_FLAG_MASK = 0x04
protocol.CLEAN_SESSION_MASK = 0x02
protocol.CONNECT_HEADER = Buffer.from([protocol.codes['connect'] << protocol.CMD_SHIFT])
function genHeader (type) {
return [0, 1, 2].map(function (qos) {
return [0, 1].map(function (dup) {
return [0, 1].map(function (retain) {
var buf = new Buffer(1)
buf.writeUInt8(
protocol.codes[type] << protocol.CMD_SHIFT |
(dup ? protocol.DUP_MASK : 0) |
qos << protocol.QOS_SHIFT | retain, 0, true)
return buf
})
})
})
}
/* Publish */
protocol.PUBLISH_HEADER = genHeader('publish')
/* Subscribe */
protocol.SUBSCRIBE_HEADER = genHeader('subscribe')
/* Unsubscribe */
protocol.UNSUBSCRIBE_HEADER = genHeader('unsubscribe')
/* Confirmations */
protocol.ACKS = {
unsuback: genHeader('unsuback'),
puback: genHeader('puback'),
pubcomp: genHeader('pubcomp'),
pubrel: genHeader('pubrel'),
pubrec: genHeader('pubrec')
}
protocol.SUBACK_HEADER = Buffer.from([protocol.codes['suback'] << protocol.CMD_SHIFT])
/* Protocol versions */
protocol.VERSION3 = Buffer.from([3])
protocol.VERSION4 = Buffer.from([4])
/* QoS */
protocol.QOS = [0, 1, 2].map(function (qos) {
return Buffer.from([qos])
})
/* Empty packets */
protocol.EMPTY = {
pingreq: Buffer.from([protocol.codes['pingreq'] << 4, 0]),
pingresp: Buffer.from([protocol.codes['pingresp'] << 4, 0]),
disconnect: Buffer.from([protocol.codes['disconnect'] << 4, 0])
}
|