module Rlp::Util
Overview
Exposes a set of utilities to ease the handling of different data types.
Defined in:
util.crClass Method Summary
-
.bin_to_hex(b : Bytes)
Converts binary bytes to a hex-encoded string.
-
.bin_to_int(b : Bytes)
Converts binary bytes to a big integer.
-
.bin_to_int(s : String)
Overloaded function
.bin_to_int
withString
to allow for conversion of decodedRlp
objects that might be a string already. -
.bin_to_int(a : Array)
Overloaded function
.bin_to_int
withArray
to allow for conversion of decodedRlp
objects that might be anRecursiveArray
. -
.bin_to_str(b : Bytes)
Converts binary bytes to a string literal.
-
.bin_to_str(s : String)
Overloaded function
.bin_to_str
withString
to allow for conversion of decodedRlp
objects that might be a string already. -
.bin_to_str(a : Array)
Overloaded function
.bin_to_str
withArray
to allow for conversion of decodedRlp
objects that might be anRecursiveArray
. -
.binary_add(a : Bytes, b : Bytes)
concatenates two byte slices of uint8
-
.hex_to_bin(h : String)
Converts hex-encoded strings to binary bytes data.
-
.hex_to_int(h : String)
Converts hex-encoded strings to big integers.
-
.hex_to_str(h : String)
Converts hex-encoded strings to string literals.
-
.int_to_bin(i : Int)
Converts big integers to binary bytes.
-
.int_to_hex(i : Int)
Converts big integers to hex-encoded strings.
-
.str_to_bin(s : String)
Converts string literals to binary bytes data.
-
.str_to_hex(s : String)
Converts string literals to hex-encoded strings.
Class Method Detail
Converts binary bytes to a hex-encoded string.
Parameters:
b
(Bytes
): the binary bytes data to convert.
Rlp::Util.bin_to_hex Bytes[4, 200, 29])
# => "04c81d"
Converts binary bytes to a big integer.
Parameters:
b
(Bytes
): the binary bytes data to convert.
Rlp::Util.bin_to_int Bytes[15, 66, 64])
# => 1000000
Overloaded function .bin_to_int
with String
to allow for conversion of
decoded Rlp
objects that might be a string already.
Parameters:
s
(String
): theRlp
string data to convert.
Rlp::Util.bin_to_int ""
# => 128
Note, that the only String
that Rlp.decode
actually returns is ""
.
Raises if s
actually contains a string. Should use .hex_to_int
instead.
Overloaded function .bin_to_int
with Array
to allow for conversion of
decoded Rlp
objects that might be an RecursiveArray
.
Raises in any case if a
actually contains an array. Shouldn't be used
if decoded Rlp
data could contain nested data structures.
Converts binary bytes to a string literal.
Parameters:
b
(Bytes
): the binary bytes data to convert.
Rlp::Util.bin_to_str Bytes[97, 98, 99])
# => "abc"
Overloaded function .bin_to_str
with String
to allow for conversion of
decoded Rlp
objects that might be a string already.
Parameters:
s
(String
): theRlp
string data to convert.
Rlp::Util.bin_to_str ""
# => ""
Overloaded function .bin_to_str
with Array
to allow for conversion of
decoded Rlp
objects that might be an RecursiveArray
.
Raises in any case if a
actually contains an array. Shouldn't be used
if decoded Rlp
data could contain nested data structures.
Converts hex-encoded strings to binary bytes data.
Parameters:
h
(String
): the hex-encoded string to convert.
Rlp::Util.hex_to_bin "04c81d"
# => Bytes[4, 200, 29]
Converts hex-encoded strings to big integers.
Parameters:
h
(String
): the hex-encoded string to convert.
Rlp::Util.hex_to_int "04c81d"
# => 313373
Converts hex-encoded strings to string literals.
Parameters:
h
(String
): the hex-encoded string to convert.
Rlp::Util.hex_to_str "646f67"
# => "dog"
Converts big integers to binary bytes.
Parameters:
i
(Int
): the big integer to convert.
Rlp::Util.int_to_bin 1_000_000
# => Bytes[15, 66, 64]
Converts big integers to hex-encoded strings.
Parameters:
i
(Int
): the big integer to convert.
Rlp::Util.int_to_hex 313_373
# => "04c81d"
Converts string literals to binary bytes data.
Parameters:
s
(String
): the string literal to convert.
Rlp::Util.str_to_bin "abc"
# => Bytes[97, 98, 99]
Converts string literals to hex-encoded strings.
Parameters:
s
(String
): the string literal to convert.
Rlp::Util.str_to_hex "dog"
# => "646f67"