Multiformats.Multicodec (multiformats_ex v0.2.0)
The primary module for fetching multicodec metadata.
Data should be generated from this source table. However, the task to generate this source file accepts any appropriately-formatted CSV file, allowing for custom codecs to be used if desired.
Summary
Functions
Decodes binary data into the codec name and the embedded data.
Encodes binary data using a codec. The codec can either be the name of the codec or the numeric representation of the codec. A numeric representation is either an integer, e.g. a codepoint or hex value, or a bitstring.
Similar to encode/2
, but raises an error if the codec is not supported.
Get a codec by either the integer/hex value or the human-readable name.
Parse the codec prefix from a binary string. Returns a tuple in the form of {codec_metadata, data}
. Will return nil
if the prefix does not match any known codec.
Functions
Decodes binary data into the codec name and the embedded data.
For example, if the binary data is prefixed with <<22>>
then the codec name returned will be "sha3-256"
.
# On a successful decode, the second element is a tuple containing the codec name and associated binary data.
{:ok, {"sha3-256", data}} = decode(<<22, ...>>)
Possible errors can occur from either an unknown codec, i.e. the prefix did not match any known codec, or the binary data was not properly varint-encoded.
Encodes binary data using a codec. The codec can either be the name of the codec or the numeric representation of the codec. A numeric representation is either an integer, e.g. a codepoint or hex value, or a bitstring.
Similar to encode/2
, but raises an error if the codec is not supported.
Get a codec by either the integer/hex value or the human-readable name.
Parse the codec prefix from a binary string. Returns a tuple in the form of {codec_metadata, data}
. Will return nil
if the prefix does not match any known codec.