-
Notifications
You must be signed in to change notification settings - Fork 119
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
FR: Provide decode_inplace function #190
Comments
https://docs.rs/base64-simd/latest/base64_simd/struct.Base64.html#method.decode_inplace fn b64decode(value: String) -> Result<Vec<u8>, base64_simd::Error> {
let base64 = base64_simd::Base64::STANDARD;
let mut vec = value.into_bytes();
let new_length = base64.decode_inplace(&mut vec)?.len();
vec.truncate(new_length);
Ok(vec)
} |
I can see the appeal in general of not requiring more memory footprint than necessary. Do you have a specific use case in mind? Does this functionality need to extend to anything beyond a function that decodes in place in order to be useful? |
There are two cases:
Function decoding in place would be sufficient.
|
Not sure about base58, but base64 decodes in front to back order in groups of 4 tokens, so that problem at least does not apply. |
Ah, sorry, I was reading this Issue thinking this was bs58 repository. Indeed, with base64 the last paragraph is not relevant. |
Would be nice to have an in-place decode function, i.e.:
Since output is never longer than input, the decoded value can be saved directly into the input buffer thus possibly saving on having to allocate a new output buffer, e.g.:
This would of course come with a caveat that if error is encountered the data in the buffer is in unspecified state (portion of it could have been overwritten).
The text was updated successfully, but these errors were encountered: