Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d19af3b

Browse files
committed
Support binary encoding in the client for more performance.
1 parent c534722 commit d19af3b

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

benchmarks/throughputCounter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var mqtt = require('../');
44

5-
var client = mqtt.createClient(1883);
5+
var client = mqtt.createClient(1883, { encoding: 'binary' });
66
var counter = 0;
77
var interval = 15000;
88

lib/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ MqttClient.prototype._setupStream = function() {
143143
this.stream = this.streamBuilder();
144144

145145
// MqttConnection
146-
this.conn = this.stream.pipe(new Connection());
146+
this.conn = this.stream.pipe(new Connection( { encoding: this.options.encoding }));
147147

148148
// Set encoding of incoming publish payloads
149149
if (this.options.encoding) {

test/abstract_client.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,33 @@ module.exports = function(server, createClient, port) {
494494
});
495495
});
496496

497+
it('should support binary data', function(done) {
498+
var client = createClient(port, { encoding: 'binary' })
499+
, testPacket = {
500+
topic: 'test',
501+
payload: 'message',
502+
retain: true,
503+
qos: 1,
504+
messageId: 5
505+
};
506+
507+
client.subscribe(testPacket.topic);
508+
client.once('message',
509+
function(topic, message, packet) {
510+
topic.should.equal(testPacket.topic);
511+
message.should.be.an.instanceOf(Buffer);
512+
message.toString().should.equal(testPacket.payload);
513+
packet.should.equal(packet);
514+
done();
515+
});
516+
517+
server.once('client', function(client) {
518+
client.on('subscribe', function(packet) {
519+
client.publish(testPacket);
520+
});
521+
});
522+
});
523+
497524
it('should emit a message event (qos=2)', function(done) {
498525
var client = createClient(port)
499526
, testPacket = {

0 commit comments

Comments
 (0)