1use std::fmt::Write;
2
3pub fn bool(input: &bool) -> String {
4 match input {
5 true => "0x01".to_string(),
6 false => "0x00".to_string()
7 }
8}
9
10pub fn str(input: &str) -> String {
11 hex(&input.to_string().into_bytes())
12}
13
14pub fn u8(input: &u8) -> String {
15 hex(&input.to_be_bytes().to_vec())
16}
17
18pub fn u16(input: &u16) -> String {
19 hex(&input.to_be_bytes().to_vec())
20}
21
22pub fn u32(arg: &u32) -> String {
23 hex(&arg.to_be_bytes().to_vec())
24}
25
26pub fn u64(input: &u64) -> String {
27 hex(&input.to_be_bytes().to_vec())
28}
29
30pub fn u128(input: &u128) -> String {
31 hex(&input.to_be_bytes().to_vec())
32}
33
34pub fn i8(input: &i8) -> String {
35 hex(&input.to_be_bytes().to_vec())
36}
37
38pub fn i16(input: &i16) -> String {
39 hex(&input.to_be_bytes().to_vec())
40}
41
42pub fn i32(input: &i32) -> String {
43 hex(&input.to_be_bytes().to_vec())
44}
45
46pub fn i64(input: &i64) -> String {
47 hex(&input.to_be_bytes().to_vec())
48}
49
50pub fn i128(input: &i128) -> String {
51 hex(&input.to_be_bytes().to_vec())
52}
53
54pub fn bytes(input: &Vec<u8>) -> String {
55 hex(input)
56}
57
58fn hex(input: &Vec<u8>) -> String {
59
60 let mut output = String::new();
61
62 output.push_str("0x");
63
64 for &byte in input {
65 write!(&mut output, "{:02X}", byte).unwrap();
66 }
67
68 output
69
70}