feat/other-formats #7

Merged
PlexSheep merged 6 commits from feat/other-formats into master 2024-05-12 18:46:11 +02:00
2 changed files with 5 additions and 14 deletions
Showing only changes of commit 24bf6cd97e - Show all commits

View File

@ -17,4 +17,5 @@ anyhow = "1.0.83"
clap = { version = "4.5.4", features = ["derive"] } clap = { version = "4.5.4", features = ["derive"] }
clap-num = "1.1.1" clap-num = "1.1.1"
fast32 = "1.0.2" fast32 = "1.0.2"
PlexSheep marked this conversation as resolved
Review

seems okay

seems okay
libpt = { version = "0.5.0", features = ["bintols"]}

View File

@ -1,3 +1,5 @@
use libpt::bintols::split;
pub type Num = u128; pub type Num = u128;
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -47,21 +49,9 @@ impl Format {
Format::Dec => { Format::Dec => {
buf += &format!("{num}"); buf += &format!("{num}");
} }
Format::Base64 => buf += &fast32::base64::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(&u128_to_u8_slice(num)), Format::Base32 => buf += &fast32::base32::RFC4648.encode(&split::unsigned_to_vec(num)),
} }
buf buf
} }
} }
PlexSheep marked this conversation as resolved Outdated

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

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`

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
}