OnFlow.Util (on_flow v0.1.0) View Source
Link to this section Summary
Functions
Decodes the given hex string to a binary. Also accepts hex strings prefixed by "0x" for convenience.
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
Specs
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"
Specs
Encodes the given binary to a hex string.
iex> encode16("")
""
iex> encode16("foo")
"666f6f"
Specs
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>>]
Specs
Trims "0x" off the given string.
iex> trim_0x("")
""
iex> trim_0x("666f6f")
"666f6f"
iex> trim_0x("0x666f6f")
"666f6f"
iex> trim_0x("0X666f6f")
"666f6f"