Skip to content

Sending Uint8Array over PUB/SUB (v4.6.0) #268

Closed
@jean-airoldie

Description

@jean-airoldie

Hi,
I am trying to figure out how to send an Uint8Array over a PUB/SUB pattern.
Currently, the array I publish differs from the one I receive. Could this be caused
by the fact that the array is not encoded into binary and instead text?

Here is a minimal working example of this issue :

const zmq = require('zeromq')
const { expect }  = require('chai')

const ZMQ_ADDR = 'tcp://127.0.0.1:5000'

let sndArr = new Uint8Array([21,31]);

let pub = zmq.socket('pub');
pub = zmq.socket('pub')
pub.bindSync(ZMQ_ADDR)

let sub = zmq.socket('sub');
sub.connect(ZMQ_ADDR);
sub.subscribe('topic');
sub.on('message', function(topic, message) {
  let recvArr = new Uint8Array(message)
  expect(recvArr.toString()).to.equal(sndArr.toString())
});

pub.send(['topic', sndArr])

Example output :

...
AssertionError: expected [ 50, 49, 44, 51, 49 ] to equal [ 21, 31 ]
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions