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

Add ability to publish byte arrays with specified offset and length. #272

Closed
igoberman opened this issue Sep 12, 2019 · 5 comments
Closed

Comments

@igoberman
Copy link

The current API only allows to publish 'whole' byte array. It means that caller has to allocate array of the precise length to make publish call. This potentially leads to a lot of GC allocations.

Could you add ability to publish array with offset and length. Something like below:

Existing:
void publish(String subject, byte[] data);
To add:
void publish(String subject, byte[] data, int offset, int length);

@sasbury
Copy link
Contributor

sasbury commented Sep 12, 2019 via email

@igoberman
Copy link
Author

Also, would be nice to have
void publish(String subject, ByteBuffer buffer);

@sasbury
Copy link
Contributor

sasbury commented Oct 24, 2019

Right now there is no way for me to let the caller reuse the bytes, because they are held in an outgoing queue until they hit the wire. I could provide helpers to copy the bytes, but I wonder if that won't be deceiving rather than helpful. What do you think?

@scottf
Copy link
Contributor

scottf commented Mar 8, 2021

@igoberman In the latest (currently unreleased) client we have an object called ByteArrayBuilder which is like StringBuilder for byte arrays and uses ByteBuffer under the covers. This object allocates the byte array as you need, is customizable (constructable) with an initial size.

Please have a look at https://github.com/nats-io/nats.java/blob/master/src/main/java/io/nats/client/impl/ByteArrayBuilder.java

@scottf
Copy link
Contributor

scottf commented Apr 30, 2021

Closing this as won't fix. See note about ByteArrayBuilder

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

4 participants