View Source OnFlow.Util (on_flow v0.13.0)
Link to this section Summary
Functions
Decodes the given hex string to a binary. Also accepts hex strings prefixed by "0x" for convenience.
Returns true
if the given term is nil
or an empty string.
Encodes the given binary to a hex string.
Pads a given binary or list of binaries with null bytes until the given binary
reaches the given byte size. direction
can be either :left
or :right
,
but defaults to :left
.
Trims "0x" off the given string.
Link to this section Functions
Decodes the given hex string to a binary. Also accepts hex strings prefixed by "0x" for convenience.
iex> decode16("")
""
iex> decode16("666f6f")
"foo"
iex> decode16("0x666f6f")
"foo"
iex> decode16("0X666f6f")
"foo"
iex> decode16("0X666f6F")
"foo"
Returns true
if the given term is nil
or an empty string.
iex> empty?(nil)
true
iex> empty?("")
true
iex> empty?(" ")
false
iex> empty?("x")
false
Encodes the given binary to a hex string.
iex> encode16("")
""
iex> encode16("foo")
"666f6f"
Pads a given binary or list of binaries with null bytes until the given binary
reaches the given byte size. direction
can be either :left
or :right
,
but defaults to :left
.
If count
is not a positive integer, the binary is returned unchanged.
iex> pad(<<91, 77>>, 4)
<<0, 0, 91, 77>>
iex> pad(<<91, 77>>, 4, :right)
<<91, 77, 0, 0>>
iex> pad([<<91, 77>>, <<129>>], 4, :right)
[<<91, 77, 0, 0>>, <<129, 0, 0, 0>>]
iex> pad([<<91, 77>>, <<129>>], 0)
[<<91, 77>>, <<129>>]
Trims "0x" off the given string.
iex> trim_0x("")
""
iex> trim_0x("666f6f")
"666f6f"
iex> trim_0x("0x666f6f")
"666f6f"
iex> trim_0x("0X666f6f")
"666f6f"