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

Binary messages are unsupported by the js pubsub API #987

Closed
roberttod opened this issue Dec 3, 2015 · 3 comments
Closed

Binary messages are unsupported by the js pubsub API #987

roberttod opened this issue Dec 3, 2015 · 3 comments
Assignees
Labels
api: pubsub Issues related to the Pub/Sub API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@roberttod
Copy link
Contributor

Messages pulled from pubsub using the subscription API are converted from base 64 to UTF 8
https://github.com/GoogleCloudPlatform/gcloud-node/blob/master/lib/pubsub/subscription.js#L298

This is fine for messages that are serialized to strings but for binary data round trips to/from UTF 8 doesn’t work http://haacked.com/archive/2012/01/30/hazards-of-converting-binary-data-to-a-string.aspx/

If there was an encoding option that defaults to utf8, receiving binary data e.g. protobuf data from a java app would be possible (currently I am having to use a fork to get this working).

I would recommend an option like so

const base64Subscription = pubsub.subscription('foo' { encoding: 'base64' })
base64Subscription.on('message', onBase64Message)

function onBase64Message (m) {
  // m.data is now a base 64 string rather than UTF 8
  const base64String = m.data
}
@stephenplusplus
Copy link
Contributor

Thanks for reporting this. That sounds like a logical way to deal with this to me. Any chance you're willing to throw a PR together?

@stephenplusplus stephenplusplus added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. api: pubsub Issues related to the Pub/Sub API. labels Dec 3, 2015
@roberttod
Copy link
Contributor Author

Sure, I am just working on it now.

@stephenplusplus
Copy link
Contributor

Fixed in #988 - thanks again!

sofisl pushed a commit that referenced this issue Jan 25, 2023
* docs: Clarify boost usage in Reference

PiperOrigin-RevId: 504332057

Source-Link: googleapis/googleapis@13dd16c

Source-Link: googleapis/googleapis-gen@75a668a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNzVhNjY4YTA1ZjVlNDM4ZmJjMDEwNWM4NTQzM2FlMTgxZWYzN2VjMCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
sofisl pushed a commit that referenced this issue Jan 25, 2023
* docs: Clarify boost usage in Reference

PiperOrigin-RevId: 504332057

Source-Link: googleapis/googleapis@13dd16c

Source-Link: googleapis/googleapis-gen@75a668a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNzVhNjY4YTA1ZjVlNDM4ZmJjMDEwNWM4NTQzM2FlMTgxZWYzN2VjMCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants