GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Change type Buffer into Uint8Array in publishMessage · Issue #1707 · googleapis/nodejs-pubsub

This repository was archived by the owner on Oct 21, 2026. It is now read-only.
This repository was archived by the owner on Oct 21, 2026. It is now read-only.

Change type Buffer into Uint8Array in publishMessage #1707

Copy link
Copy link
Closed
#2020
Closed
Change type Buffer into Uint8Array in publishMessage#1707
#2020
Copy link
Assignees
feywind
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.

Description

@seo-rii
seo-rii
opened on Apr 11, 2023
Issue body actions

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
.

Activity

  1. seo-rii
    added
    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.
    on Apr 11, 2023
  2. product-auto-label
    added
    api: pubsubIssues related to the googleapis/nodejs-pubsub API.
    on Apr 11, 2023
  3. seo-rii
    changed the title [-]Change type buffer into Uint8Array in publishMessage[/-] [+]Change type Buffer into Uint8Array in publishMessage[/+] on Apr 11, 2023
  4. feywind commented on Apr 12, 2023

    @feywind
    feywind
    on Apr 12, 2023
    Contributor
    More actions

    @seo-rii Ah, interesting, that doesn't seem unreasonable, though we'd have to make sure the gapic classes will also work with array buffers. I'm curious, if you don't mind sharing more detail, what your code's general workflow is like, that it would benefit from the fix. I'm asking mostly because we're working on a v2 version of the API and I'd like to make sure the common use cases are covered.

  5. seo-rii commented on Apr 13, 2023

    @seo-rii
    seo-rii
    on Apr 13, 2023
    Author
    More actions

    I'm trying to deliver a message encoded in protobuf to pubsub and deliver that binary message to all users in same channel. Like this : (await topic(chan)).publishMessage({data: encode(obj)});
    But the value returned by protobuf.js module is Uint8Array, the code must be modified as follows.

    const m = encode(obj), data = Buffer.alloc(m.byteLength);
    for (let i = 0; i < m.byteLength; i++) data[i] = m[i];
    await (await topic(chan)).publishMessage({data});

    This creates a copy operation that looks very unnecessary, and adversely affects both code execution time and memory usage.

  6. kamalaboulhosn
    assigned
    feywind
    on Oct 23, 2023
  7. datadanne commented on Feb 14, 2025

    @datadanne
    datadanne
    on Feb 14, 2025
    More actions

    Bumping this! Any ETA on a fix?

    Quite annoying to have to do { data: Buffer.from(myData) as unknown as UInt8Array } to get tsc to pass

    Reacted by Idris Akintobi
  8. feywind
    closed this as completedin #2020on Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @feywind
    feywind

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.