updated comments
This commit is contained in:
+4
-3
@@ -8,16 +8,16 @@ pub fn encode(bytes: Vec<u8>) -> String {
|
||||
let b1 = chunk.get(1).copied().unwrap_or(0) as u32;
|
||||
let b2 = chunk.get(2).copied().unwrap_or(0) as u32;
|
||||
|
||||
// 24-bit number
|
||||
// make 24-bit number from 3 Bytes
|
||||
let triple = (b0 << 16) | (b1 << 8) | b2;
|
||||
|
||||
// in 6-bit indices
|
||||
// pull out 6-bit indices
|
||||
let i0 = ((triple >> 18) & 0x3F) as usize;
|
||||
let i1 = ((triple >> 12) & 0x3F) as usize;
|
||||
let i2 = ((triple >> 6) & 0x3F) as usize;
|
||||
let i3 = (triple & 0x3F) as usize;
|
||||
|
||||
// at least 1 chunk of 8-bit input
|
||||
// at least 1 chunk of 8-bit input is guaranteed valid
|
||||
// so at least 2 chunks of 6-bit window is valid
|
||||
output.push(BASE64_ALPHABET[i0] as char);
|
||||
output.push(BASE64_ALPHABET[i1] as char);
|
||||
@@ -57,4 +57,5 @@ mod tests {
|
||||
let base64 = encode(bytes);
|
||||
assert_eq!(base64, String::from("Zg=="));
|
||||
}
|
||||
// todo: add more tests
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user