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

Allow user to specify buffer by adding cbor.MarshalToBuffer(), UserBufferEncMode interface, etc. #553

Merged
merged 1 commit into from
Jun 10, 2024

Conversation

fxamacker
Copy link
Owner

Currently, the encoder uses a built-in buffer pool. This PR allows encoding to a user specified buffer rather than using the built-in buffer pool.

This PR wraps and uses a function implemented in PR #521 by @benluddy. Thanks Ben! 👍

This PR adds:

  • cbor.MarshalToBuffer() uses codec's default options to encode to user provided buffer instead of using built-in buffer pool.

  • UserBufferEncMode interface extends EncMode interface with MarshalToBuffer() so user can provide buffer for encoding instead of using built-in buffer pool.

  • EncOptions.UserBufferEncMode() returns UserBufferEncMode

  • EncOptions.UserBufferEncModeWithTags() returns UserBufferEncMode

  • EncOptions.UserBufferEncModeWithSharedTags() returns UserBufferEncMode

This PR added a check to return error if user provided buffer *bytes.Buffer is nil.

This commit adds features related to allowing user to specify
a buffer rather than using built-in buffer pool:

- cbor.MarshalToBuffer() uses codec's default options to encode
  to user provided buffer instead of using built-in buffer pool.

- UserBufferEncMode interface extends EncMode interface with
  MarshalToBuffer() so user can provide buffer for encoding
  instead of using built-in buffer pool.

- EncOptions.UserBufferEncMode() returns UserBufferEncMode

- EncOptions.UserBufferEncModeWithTags() returns UserBufferEncMode

- EncOptions.UserBufferEncModeWithSharedTags() returns UserBufferEncMode
@fxamacker fxamacker added the enhancement New feature or request label Jun 10, 2024
@fxamacker fxamacker added this to the v2.7.0 milestone Jun 10, 2024
@fxamacker fxamacker self-assigned this Jun 10, 2024
@fxamacker
Copy link
Owner Author

@benluddy @x448 PTAL 🙏

Copy link
Contributor

@x448 x448 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🚀

@fxamacker fxamacker merged commit 8ac5347 into master Jun 10, 2024
20 checks passed
@fxamacker fxamacker deleted the fxamacker/add-userbufferencmode-interface branch September 7, 2024 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants