-
Notifications
You must be signed in to change notification settings - Fork 158
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
Comments
I will take a look for the next release
…On Thu, Sep 12, 2019, 8:31 AM igoberman ***@***.***> wrote:
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);
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#272?email_source=notifications&email_token=AAZIPULU65RWX5LYVOYIEXLQJJOGHA5CNFSM4IWGE6SKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HLAYKSQ>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAZIPULNOIYXR25POPHOFDLQJJOGHANCNFSM4IWGE6SA>
.
|
Also, would be nice to have |
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? |
@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 |
Closing this as won't fix. See note about ByteArrayBuilder |
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);
The text was updated successfully, but these errors were encountered: