Skip to content

RUST-2258 Use borrowed buffer in raw serializer #590

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

Merged
merged 2 commits into from
Aug 13, 2025

Conversation

LeWimbes
Copy link
Contributor

@LeWimbes LeWimbes commented Aug 6, 2025

Similar to the idea in #328, raw::Serializer now takes a &mut Vec<u8>.
Because the Vec is borrowed, the same buffer can be reused for many serializations without reallocating.

  • added serialize_to_buffer: serialize &T straight into a caller-supplied Vec<u8>.
  • serialize_to_vec still exists. It just allocates a Vec<u8> and forwards it to serialize_to_buffer.

Breaking change: raw::Serializer::new() now expects &mut Vec<u8>.

@LeWimbes LeWimbes requested a review from a team as a code owner August 6, 2025 15:13
@LeWimbes LeWimbes requested a review from isabelatkinson August 6, 2025 15:13
@isabelatkinson isabelatkinson changed the title Borrow the buffer instead of owning it RUST-2258 Use borrowed buffer in raw serializer Aug 6, 2025
Copy link
Contributor

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I pushed a fix for a few lint errors and CI is now passing. Going to tag in the other team member for review.

@isabelatkinson isabelatkinson requested a review from abr-egn August 12, 2025 15:52
@isabelatkinson isabelatkinson merged commit 93b391c into mongodb:main Aug 13, 2025
12 checks passed
@LeWimbes LeWimbes deleted the serialize_to_buffer branch August 13, 2025 14:53
@LeWimbes
Copy link
Contributor Author

Thanks for fixing the lints and merging. I think #328 can be closed now, since it provides similar functionality.

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