generated from PlexSheep/rs-base
feat/other-formats #7
|
@ -17,4 +17,5 @@ anyhow = "1.0.83"
|
|||
clap = { version = "4.5.4", features = ["derive"] }
|
||||
clap-num = "1.1.1"
|
||||
fast32 = "1.0.2"
|
||||
PlexSheep marked this conversation as resolved
|
||||
libpt = { version = "0.5.0", features = ["bintols"]}
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use libpt::bintols::split;
|
||||
|
||||
pub type Num = u128;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
@ -47,21 +49,9 @@ impl Format {
|
|||
Format::Dec => {
|
||||
buf += &format!("{num}");
|
||||
}
|
||||
Format::Base64 => buf += &fast32::base64::RFC4648.encode(&u128_to_u8_slice(num)),
|
||||
Format::Base32 => buf += &fast32::base32::RFC4648.encode(&u128_to_u8_slice(num)),
|
||||
Format::Base64 => buf += &fast32::base64::RFC4648.encode(&split::unsigned_to_vec(num)),
|
||||
Format::Base32 => buf += &fast32::base32::RFC4648.encode(&split::unsigned_to_vec(num)),
|
||||
}
|
||||
buf
|
||||
}
|
||||
}
|
||||
PlexSheep marked this conversation as resolved
Outdated
PlexSheep
commented
This seems like a fairly common thing to do, perhaps we can use a dependency for this? If it does not exist, it might be a good fit for This seems like a fairly common thing to do, perhaps we can use a dependency for this?
If it does not exist, it might be a good fit for `libpt-bintols`
PlexSheep
commented
Issue for pt was created: PlexSheep/pt#76 Issue for pt was created: https://git.cscherr.de/PlexSheep/pt/issues/76
|
||||
|
||||
fn u128_to_u8_slice(mut num: u128) -> Vec<u8> {
|
||||
if num == 0 {
|
||||
return vec![0];
|
||||
}
|
||||
let mut buf: Vec<u8> = Vec::new();
|
||||
while num > 0 {
|
||||
buf.push(num as u8);
|
||||
num >>= 8;
|
||||
}
|
||||
buf
|
||||
}
|
||||
|
|
Reference in New Issue
seems okay