Skip to content

Change type Buffer into Uint8Array in publishMessage #1707

@seo-rii

Description

@seo-rii

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Is your feature request related to a problem? Please describe.
In publishMessage method of Topic, it checks if data is instance of Buffer.
Some of modern serialization library uses Uint8Array as return value instead of Buffer. Although we can change it into Buffer using Buffer.from, it will copy Arraybuffer, which causes performance issue.
Since Buffer is subclass of Uint8Array, I think it can be changed into data && !(data instanceof Uint8Array).

Describe the solution you'd like
Change src/publisher/index.ts L195 into if (data && !(data instanceof Uint8Array)) {.

Describe alternatives you've considered
We can change Uint8Array into Buffer using Buffer.frommethod, but it will 'copy' array and create new one.

Additional context
.

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the googleapis/nodejs-pubsub API.priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions