IOData protocol (iodata v0.7.2)
A protocol for working with various data types such as binaries and iolists.
This protocol defines a set of functions for performing common operations on data, including:
- Checking if the data has at least a specified number of bytes.
- Retrieving the size of the data in bytes.
- Splitting the data at a specified byte offset.
- Checking if the data starts with a given binary prefix.
- Converting the data to iodata or binary formats.
- Extracting portions of the data as iodata or binary.
Implementations of this protocol should be efficient and avoid unnecessary copying of data whenever possible.
Summary
Functions
Checks if the given data has at least the specified number of bytes.
Returns the total size, in bytes, of the given data.
Returns a slice of the data, with a tuple that defines the start and count of bytes to extract.
Returns a slice of the data, starting at 'start' for 'count' bytes.
Same as slice/2 but raises an error if the data is insufficient.
Same as slice/3 but raises an error if the data is insufficient.
Splits data at the specified byte offset if possible, returning either {:ok, {prefix, suffix}} or an error tuple.
Same as split/2 but raises an error if the data is insufficient.
Checks if the given data starts with the specified binary prefix.
Converts the entire data into a binary.
Extracts a portion of the data as a binary, starting at 'start' for 'count' bytes. Returns an ok/error tuple.
Same as to_binary/1 but raises an error if the data is insufficient.
Same as to_binary/3 but raises an error if the data is insufficient.
Returns the data in iodata form without modifying it.
Extracts a portion of the data as iodata, starting at 'start' for 'count' bytes. Returns an ok/error tuple.
Same as to_iodata/1 but raises an error if the data is insufficient.
Same as to_iodata/3 but raises an error if the data is insufficient.
Types
@type t() :: term()
Functions
@spec at_least?(t(), n_bytes :: non_neg_integer()) :: boolean()
Checks if the given data has at least the specified number of bytes.
@spec size(t()) :: non_neg_integer()
Returns the total size, in bytes, of the given data.
@spec slice( t(), {start :: non_neg_integer(), count :: non_neg_integer()} ) :: {:ok, t()} | {:error, reason :: term()}
Returns a slice of the data, with a tuple that defines the start and count of bytes to extract.
@spec slice(t(), start :: non_neg_integer(), count :: non_neg_integer()) :: {:ok, t()} | {:error, reason :: term()}
Returns a slice of the data, starting at 'start' for 'count' bytes.
@spec slice!( t(), {start :: non_neg_integer(), count :: non_neg_integer()} ) :: t()
Same as slice/2 but raises an error if the data is insufficient.
@spec slice!(t(), start :: non_neg_integer(), count :: non_neg_integer()) :: t()
Same as slice/3 but raises an error if the data is insufficient.
@spec split(t(), non_neg_integer()) :: {:ok, {t(), t()}} | {:error, :insufficient_data}
Splits data at the specified byte offset if possible, returning either {:ok, {prefix, suffix}} or an error tuple.
@spec split!(t(), non_neg_integer()) :: {t(), t()}
Same as split/2 but raises an error if the data is insufficient.
Checks if the given data starts with the specified binary prefix.
Converts the entire data into a binary.
@spec to_binary(t(), start :: non_neg_integer(), count :: non_neg_integer()) :: {:ok, binary()} | {:error, :insufficient_data}
Extracts a portion of the data as a binary, starting at 'start' for 'count' bytes. Returns an ok/error tuple.
Same as to_binary/1 but raises an error if the data is insufficient.
@spec to_binary!(t(), start :: non_neg_integer(), count :: non_neg_integer()) :: binary()
Same as to_binary/3 but raises an error if the data is insufficient.
Returns the data in iodata form without modifying it.
@spec to_iodata(t(), start :: non_neg_integer(), count :: non_neg_integer()) :: {:ok, t()} | {:error, :insufficient_data}
Extracts a portion of the data as iodata, starting at 'start' for 'count' bytes. Returns an ok/error tuple.
Same as to_iodata/1 but raises an error if the data is insufficient.
@spec to_iodata!(t(), start :: non_neg_integer(), count :: non_neg_integer()) :: iodata()
Same as to_iodata/3 but raises an error if the data is insufficient.