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 using user-supplied buffer for encoding data? #72

Closed
repnop opened this issue Feb 11, 2022 · 3 comments · Fixed by #106
Closed

Allow using user-supplied buffer for encoding data? #72

repnop opened this issue Feb 11, 2022 · 3 comments · Fixed by #106
Labels
area/codec Related to a new or existing ASN.1 codec. good first issue Good for newcomers help wanted Extra attention is needed kind/enhancement New feature or request

Comments

@repnop
Copy link
Contributor

repnop commented Feb 11, 2022

Hi, I'm working on building a SNMP client and as an optimization to prevent allocating memory on every send/receive, I want to internally store a Vec in my client, however there doesn't appear to be a way to provide the Encoder a &mut Vec<u8> or &mut [u8] to encode into, which would be really useful!

@repnop
Copy link
Contributor Author

repnop commented Feb 11, 2022

An alternative might be to allow passing a Vec<u8> into a constructor for Encoder, which would allow me to core::mem::take(&mut self.my_buffer); then swap it back after encoding -- not entirely ideal, but definitely workable and much easier to adapt Encoder to. If you'd be fine with this method if the above seems more difficult to support, I'd happily PR it!

@XAMPPRocky
Copy link
Collaborator

Thank you for your issue! Sorry for the late reply. Overall I'm open to adding a way for to re-use the encoder buffer and would accept a PR adding this functionality. I'll only note that this won't entirely prevent allocating on every send/receive depending on the data. There are ASN.1 types that rasn always has to allocate in order to handle correctly at the layer its operating at (the main one being SET types). Being able to re-use the buffer would still be useful for cases where those types aren't present however.

@XAMPPRocky XAMPPRocky added kind/enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Mar 9, 2022
@repnop
Copy link
Contributor Author

repnop commented Mar 9, 2022

Awesome! I'll see if I can find some spare time and send in a PR for that 👍

@XAMPPRocky XAMPPRocky added the area/codec Related to a new or existing ASN.1 codec. label May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codec Related to a new or existing ASN.1 codec. good first issue Good for newcomers help wanted Extra attention is needed kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants