tangled
alpha
login
or
join now
da157.id
/
porcelain
0
fork
atom
cli dollcode encoder and decoder
0
fork
atom
overview
issues
pulls
pipelines
fix support for disabling bigint
0xda157
2 weeks ago
28597c50
c2631dc4
+46
-38
2 changed files
expand all
collapse all
unified
split
Cargo.toml
src
main.rs
+2
-2
Cargo.toml
···
16
17
[features]
18
default = ["bigint"]
19
-
bigint = ["dep:num"]
20
21
[dependencies]
22
-
lib-porcelain = { path = "./lib-porcelain", version = "0.2.1", features = [ "num" ] }
23
clap = { version = "4.5.51", features = ["cargo"] }
24
num = { version = "0.4.3", optional = true }
···
16
17
[features]
18
default = ["bigint"]
19
+
bigint = ["dep:num", "lib-porcelain/num"]
20
21
[dependencies]
22
+
lib-porcelain = { path = "./lib-porcelain", version = "0.2.1" }
23
clap = { version = "4.5.51", features = ["cargo"] }
24
num = { version = "0.4.3", optional = true }
+44
-36
src/main.rs
···
29
let input = ematches.get_one::<String>("input").unwrap();
30
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
-
39
println!(
40
"{}",
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
-
})
45
);
0
0
0
0
0
0
0
0
46
return;
47
}
48
49
if let Some(s) = input.strip_prefix("0x") {
0
50
println!(
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
-
})
0
0
60
);
61
return;
62
}
63
64
if ematches.get_flag("hex") {
0
65
println!(
66
"{}",
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
-
})
0
0
75
);
76
return;
77
}
78
0
79
println!(
80
"{}",
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
-
})
0
0
90
);
91
}
92
···
29
let input = ematches.get_one::<String>("input").unwrap();
30
31
if ematches.get_flag("string") {
32
+
#[cfg(feature = "bigint")]
0
0
0
0
0
0
33
println!(
34
"{}",
35
+
BigUint::from_bytes_be(input.clone().as_bytes()).to_dollcode()
0
0
0
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
+
45
return;
46
}
47
48
if let Some(s) = input.strip_prefix("0x") {
49
+
#[cfg(feature = "bigint")]
50
println!(
51
"{}",
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()
62
);
63
return;
64
}
65
66
if ematches.get_flag("hex") {
67
+
#[cfg(feature = "bigint")]
68
println!(
69
"{}",
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(),
80
);
81
return;
82
}
83
84
+
#[cfg(feature = "bigint")]
85
println!(
86
"{}",
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()
98
);
99
}
100