Before you file an issue
- Did you read the docs? yes, and it only has
encode_string,
- Did you read the README? yes, and it doesn't seem to have a mention about this
The problem
Let's say I want to write using a specific file format that has base64 interspersed with non-utf8 bytes:
......binary stuff......dmFsaWQgYmFzZTY0Cg==......more binary stuff......
Currently this is a bit tricky to do efficiently. None of the current Engine methods have a thing that supports outputting into a &mut Vec<u8>:
encode(T) -> String allocates a whole new string, and I'd have to copy it over to my buffer.
encode_string(T, &mut String) takes in a &mut String so it may not have to reallocate... but I don't have a String here; I only have a Vec<u8> buffer.
encode_slice(T, &mut [u8]) could kinda work? I'd have to extend my Vec<u8> with zeroes, then slice into those zeroes, making sure it has a sufficient size or else it'll return an error.
It would be a lot more convenient if there were an encode_vec(T, &mut Vec<u8>) method. Not only would this skip zeroing out the memory, it also means unlike encode_slice there's not really a reason for it to fail (besides allocator failures but ehhhh)
How I, the issue filer, am going to help solve it
By proposing this function to be added.
Not a Duplicate (probably)
I actually saw issue #257 about adding encode_base64(input: &[u8]) -> Vec<u8>. This allocates a new Vec. Meanwhile I'm actually suggesting a way to append to an existing Vec. So I don't think this is a duplicate. I didn't really find much else about encoding to Vecs when searching for "Vec" in the issue tracker, but maybe I missed something?
Before you file an issue
encode_string,The problem
Let's say I want to write using a specific file format that has base64 interspersed with non-utf8 bytes:
Currently this is a bit tricky to do efficiently. None of the current
Enginemethods have a thing that supports outputting into a&mut Vec<u8>:encode(T) -> Stringallocates a whole new string, and I'd have to copy it over to my buffer.encode_string(T, &mut String)takes in a&mut Stringso it may not have to reallocate... but I don't have aStringhere; I only have aVec<u8>buffer.encode_slice(T, &mut [u8])could kinda work? I'd have to extend myVec<u8>with zeroes, then slice into those zeroes, making sure it has a sufficient size or else it'll return an error.It would be a lot more convenient if there were an
encode_vec(T, &mut Vec<u8>)method. Not only would this skip zeroing out the memory, it also means unlikeencode_slicethere's not really a reason for it to fail (besides allocator failures but ehhhh)How I, the issue filer, am going to help solve it
By proposing this function to be added.
Not a Duplicate (probably)
I actually saw issue #257 about adding
encode_base64(input: &[u8]) -> Vec<u8>. This allocates a newVec. Meanwhile I'm actually suggesting a way to append to an existingVec. So I don't think this is a duplicate. I didn't really find much else about encoding toVecs when searching for "Vec" in the issue tracker, but maybe I missed something?