Skip to content

FR: Provide decode_inplace function #190

Open
@mina86

Description

Would be nice to have an in-place decode function, i.e.:

fn decode_inplace(data: &mut [u8]) -> Result<usize, DecodeError> {}

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.:

fn b64decode(value: String) -> Result<Vec<u8>, base64::DecodeError> {
    let mut vec = value.into_bytes();
    let new_length = base64::decode_inplace(&mut vec[..])?;
    vec.truncate(new_length);
    Ok(vec)
}

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).

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions