cli dollcode encoder and decoder

fix support for disabling bigint

0xda157 28597c50 c2631dc4

+46 -38
+2 -2
Cargo.toml
··· 16 16 17 17 [features] 18 18 default = ["bigint"] 19 - bigint = ["dep:num"] 19 + bigint = ["dep:num", "lib-porcelain/num"] 20 20 21 21 [dependencies] 22 - lib-porcelain = { path = "./lib-porcelain", version = "0.2.1", features = [ "num" ] } 22 + lib-porcelain = { path = "./lib-porcelain", version = "0.2.1" } 23 23 clap = { version = "4.5.51", features = ["cargo"] } 24 24 num = { version = "0.4.3", optional = true }
+44 -36
src/main.rs
··· 29 29 let input = ematches.get_one::<String>("input").unwrap(); 30 30 31 31 if ematches.get_flag("string") { 32 - let std_int = |s: &str| { 33 - let mut buf = [0u8; 8]; 34 - let len = 8.min(s.len()); 35 - buf[..len].copy_from_slice(&s.as_bytes()[..len]); 36 - u64::from_be_bytes(buf) 37 - }; 38 - 32 + #[cfg(feature = "bigint")] 39 33 println!( 40 34 "{}", 41 - (match cfg!(feature = "bigint") { 42 - true => BigUint::from_bytes_be(input.clone().as_bytes()).to_dollcode(), 43 - false => std_int(input).to_dollcode(), 44 - }) 35 + BigUint::from_bytes_be(input.clone().as_bytes()).to_dollcode() 45 36 ); 37 + #[cfg(not(feature = "bigint"))] 38 + println!("{}", { 39 + let mut buf = [0u8; 8]; 40 + let len = 8.min(input.len()); 41 + buf[..len].copy_from_slice(&input.as_bytes()[..len]); 42 + u64::from_be_bytes(buf).to_dollcode() 43 + }); 44 + 46 45 return; 47 46 } 48 47 49 48 if let Some(s) = input.strip_prefix("0x") { 49 + #[cfg(feature = "bigint")] 50 50 println!( 51 51 "{}", 52 - (match cfg!(feature = "bigint") { 53 - true => BigUint::from_str_radix(s, 16) 54 - .expect("invalid hex") 55 - .to_dollcode(), 56 - false => u64::from_str_radix(s, 16) 57 - .expect("invalid hex") 58 - .to_dollcode(), 59 - }) 52 + BigUint::from_str_radix(s, 16) 53 + .expect("invalid hex") 54 + .to_dollcode() 55 + ); 56 + #[cfg(not(feature = "bigint"))] 57 + println!( 58 + "{}", 59 + u64::from_str_radix(s, 16) 60 + .expect("invalid hex") 61 + .to_dollcode() 60 62 ); 61 63 return; 62 64 } 63 65 64 66 if ematches.get_flag("hex") { 67 + #[cfg(feature = "bigint")] 65 68 println!( 66 69 "{}", 67 - (match cfg!(feature = "bigint") { 68 - true => BigUint::from_str_radix(input, 16) 69 - .expect("invalid hex") 70 - .to_dollcode(), 71 - false => u64::from_str_radix(input, 16) 72 - .expect("invalid hex") 73 - .to_dollcode(), 74 - }) 70 + BigUint::from_str_radix(input, 16) 71 + .expect("invalid hex") 72 + .to_dollcode() 73 + ); 74 + #[cfg(not(feature = "bigint"))] 75 + println!( 76 + "{}", 77 + u64::from_str_radix(input, 16) 78 + .expect("invalid hex") 79 + .to_dollcode(), 75 80 ); 76 81 return; 77 82 } 78 83 84 + #[cfg(feature = "bigint")] 79 85 println!( 80 86 "{}", 81 - (match cfg!(feature = "bigint") { 82 - true => BigUint::from_str(input) 83 - .expect("input must be declared as hex or be a decimial number") 84 - .to_dollcode(), 85 - false => input 86 - .parse::<u64>() 87 - .expect("input must be declared as hex or be a decimial number") 88 - .to_dollcode(), 89 - }) 87 + BigUint::from_str(input) 88 + .expect("input must be declared as hex or be a decimial number") 89 + .to_dollcode() 90 + ); 91 + #[cfg(not(feature = "bigint"))] 92 + println!( 93 + "{}", 94 + input 95 + .parse::<u64>() 96 + .expect("input must be declared as hex or be a decimial number") 97 + .to_dollcode() 90 98 ); 91 99 } 92 100