bsv_rpc v1.0.0-alpha3 BsvRpc.Helpers View Source
Various helper functions.
Link to this section Summary
Functions
Gets the double sha256 hash of the input data.
Gets variable length integer from the beginning of a binary.
Gets variable length data (defines with variable length prefix bytes) from the beginning of the binary.
Converts endianess of a binary blob.
Gets variable length integer representation of a number.
Prefixed data with the varlen prefix.
Link to this section Functions
Gets the double sha256 hash of the input data.
Examples
iex> BsvRpc.Helpers.double_sha256(<<>>) <<93, 246, 224, 226, 118, 19, 89, 211, 10, 130, 117, 5, 142, 41, 159, 204, 3,
129, 83, 69, 69, 245, 92, 244, 62, 65, 152, 63, 93, 76, 148, 86>>
iex> BsvRpc.Helpers.double_sha256(<<0, 0, 0, 0>>) <<140, 185, 1, 37, 23, 200, 23, 254, 173, 101, 2, 135, 214, 27, 221, 156, 104,
128, 59, 107, 249, 198, 65, 51, 220, 171, 62, 101, 181, 165, 12, 185>>
iex(4)> BsvRpc.Helpers.double_sha256(<<0xff, 0xff, 0xff, 0xff>>) <<59, 177, 48, 41, 206, 123, 31, 85, 158, 245, 231, 71, 252, 172, 67, 159, 20,
85, 162, 236, 124, 95, 9, 183, 34, 144, 121, 94, 112, 102, 80, 68>>
get_varint(arg)
View Sourceget_varint(binary()) :: {non_neg_integer(), binary()}
Gets variable length integer from the beginning of a binary.
Examples
iex> BsvRpc.Helpers.get_varint(<<0x01>>) {1, <<>>}
iex> BsvRpc.Helpers.get_varint(<<0xFD, 0x80, 0x00, 0x12, 0x34>>) {128, <<0x12, 0x34>>}
iex> BsvRpc.Helpers.get_varint(<<0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x00>>) {4294967295, <<0x00>>}
iex> BsvRpc.Helpers.get_varint(<<0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEE>>) {18446744073709551615, <<0xEE>>}
Gets variable length data (defines with variable length prefix bytes) from the beginning of the binary.
Returns a tuple with the variable length data as the first element and the rest of the original binary as the second.
Examples
iex> BsvRpc.Helpers.get_varlen_data(<<0x01, 0xFF, 0xEE>>) {<<255>>, <<0xEE>>}
iex> BsvRpc.Helpers.get_varlen_data(<<0xFD, 0x01, 0x00, 0xEE, 0x34>>) {<<0xEE>>, <<0x34>>}
Converts endianess of a binary blob.
Examples
iex> BsvRpc.Helpers.reverse_endianess(<<0xff, 0xee, 0xdd, 0xcc>>) <<0xcc, 0xdd, 0xee, 0xff>>
iex> BsvRpc.Helpers.reverse_endianess(<<0x00, 0x11, 0x22, 0x33>>) <<0x33, 0x22, 0x11, 0x00>>
Gets variable length integer representation of a number.
Examples
iex> BsvRpc.Helpers.to_varint(1) <<0x01>>
iex> BsvRpc.Helpers.to_varint(32768) <<0xFD, 0x00, 0x80>>
iex> BsvRpc.Helpers.to_varint(4294967295) <<0xFE, 0xFF, 0xFF, 0xFF, 0xFF>>
iex> BsvRpc.Helpers.to_varint(18446744073709551615) <<0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF>>
Prefixed data with the varlen prefix.
Examples
iex> BsvRpc.Helpers.to_varlen_data(<<0xff, 0xee>>) <<0x02, 0xff, 0xee>>
iex> BsvRpc.Helpers.to_varlen_data(<<0xff>>) <<0x01, 0xff>>