module Rlp::Util

Overview

Exposes a set of utilities to ease the handling of different data types.

Defined in:

util.cr

Class Method Summary

Class Method Detail

def self.bin_to_hex(b : Bytes) #

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"

[View source]
def self.bin_to_int(b : Bytes) #

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

[View source]
def self.bin_to_int(s : String) #

Overloaded function .bin_to_int with String to allow for conversion of decoded Rlp objects that might be a string already.

Parameters:

  • s (String): the Rlp 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.


[View source]
def self.bin_to_int(a : Array) #

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.


[View source]
def self.bin_to_str(b : Bytes) #

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"

[View source]
def self.bin_to_str(s : String) #

Overloaded function .bin_to_str with String to allow for conversion of decoded Rlp objects that might be a string already.

Parameters:

  • s (String): the Rlp string data to convert.
Rlp::Util.bin_to_str ""
# => ""

[View source]
def self.bin_to_str(a : Array) #

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.


[View source]
def self.binary_add(a : Bytes, b : Bytes) #

concatenates two byte slices of uint8


[View source]
def self.hex_to_bin(h : String) #

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]

[View source]
def self.hex_to_int(h : String) #

Converts hex-encoded strings to big integers.

Parameters:

  • h (String): the hex-encoded string to convert.
Rlp::Util.hex_to_int "04c81d"
# => 313373

[View source]
def self.hex_to_str(h : String) #

Converts hex-encoded strings to string literals.

Parameters:

  • h (String): the hex-encoded string to convert.
Rlp::Util.hex_to_str "646f67"
# => "dog"

[View source]
def self.int_to_bin(i : Int) #

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]

[View source]
def self.int_to_hex(i : Int) #

Converts big integers to hex-encoded strings.

Parameters:

  • i (Int): the big integer to convert.
Rlp::Util.int_to_hex 313_373
# => "04c81d"

[View source]
def self.str_to_bin(s : String) #

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]

[View source]
def self.str_to_hex(s : String) #

Converts string literals to hex-encoded strings.

Parameters:

  • s (String): the string literal to convert.
Rlp::Util.str_to_hex "dog"
# => "646f67"

[View source]