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

Encoder::buffer_filled and ::len_filled #72

Merged

Conversation

jgraef
Copy link
Contributor

@jgraef jgraef commented Jun 6, 2024

This PR adds two methods to the Encoder:

  • buffer_filled: returns only the portion of the buffer that was written to, i.e. the serialized message.
  • len_filled: returns the number of bytes that have been written.

In my usecase I'm reusing a buffer for sending/receiving. I don't want to truncate the buffer to length 0, just to have to grow (and thus initialize) it later again. Encoder writes to the buffer from the beginning anyway and only grows it as needed. If the buffer was larger that the serialized message, the buffer() method will still return the whole buffer, including any garbage at the end of the buffer.

With buffer_filled and len_filled you can easily get a slice of the serialized message.

@stappersg
Copy link

There only a commit summary, please extend the commit message.
(FYI: I'm not project lead, just some random Joe how cares about this project.)

@leshow
Copy link
Collaborator

leshow commented Jun 6, 2024

lgtm, thanks!

@leshow leshow merged commit c775948 into bluecatengineering:master Jun 6, 2024
3 of 9 checks passed
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

Successfully merging this pull request may close these issues.

3 participants