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