The following code to decode a u64 from base64 works fine but is quite ugly:
let mut array = [0u8; 9];
base64_url::decode_to_slice(str_rep, &mut array).expect("Not a valid base64 encoding");
u64::from_le_bytes(array[..8].try_into().unwrap())
The problem here is that the encoded u64 is 11 characters which amounts to 66 bits, not 64. Ideally, I would like to have a decode function that can set the length explicitly or detects it based on the size of the slice.
For example, this would look much nicer:
let mut array = [0u8; std::mem::size_of::<u64>()];
base64_url::decode_to_slice_with_length(str_rep, &mut array, u64::BITS).expect("Not a valid base64 encoding");
u64::from_le_bytes(array)
The following code to decode a u64 from base64 works fine but is quite ugly:
The problem here is that the encoded u64 is 11 characters which amounts to 66 bits, not 64. Ideally, I would like to have a decode function that can set the length explicitly or detects it based on the size of the slice.
For example, this would look much nicer: