Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when publishing binary buffer or Uint8Array #7

Open
andreap2018 opened this issue Jun 29, 2021 · 1 comment
Open

Issue when publishing binary buffer or Uint8Array #7

andreap2018 opened this issue Jun 29, 2021 · 1 comment

Comments

@andreap2018
Copy link

andreap2018 commented Jun 29, 2021

When trying to publish a proto binary buffer the object is converted to JSON string, but it should be published as it is since the client supports buffer / Uint8Array

One way to do it is to change the condition as follow:

  if (typeof message === 'object' && !Buffer.isBuffer(message)) {
    message = JSON.stringify(message);
  }

Is it possible to apply this change ?
Thanks
Andrea

Code from mqtt.service.ts :

  publish(topic: string, message: string | Buffer | object, opts?: IClientPublishOptions): Promise<Packet> {
    return new Promise<Packet>((resolve, reject) => {
      if (typeof message === 'object') {
        message = JSON.stringify(message);
      }
      this.client.publish(topic, message, opts || null, (error, packet) => {
        if (error) {
          reject(error);
        } else {
          resolve(packet);
        }
      });
    });
  }
@microud
Copy link
Owner

microud commented Jul 6, 2021

Thanks for your opinion. Welcome for your pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants