View Source Bento.Decoder (bento v1.0.0)

Useful wrapper for Bento.Parser.

Link to this section Summary

Functions

Decode a bencoded value.

Decode a bencoded value, but raise an error if it fails.

Transform a parsed value into a struct.

Link to this section Types

@type decode_err() :: Bento.Parser.parse_err()
@type opts() :: [{:as, map() | list() | struct()}]
@type t() :: Bento.Parser.t() | struct()

Link to this section Functions

Link to this function

decode(value, opts \\ [])

View Source
@spec decode(iodata(), opts()) :: {:ok, t()} | {:error, decode_err()}

Decode a bencoded value.

Link to this function

decode!(value, opts \\ [])

View Source
@spec decode!(iodata(), opts()) :: t() | no_return()

Decode a bencoded value, but raise an error if it fails.

@spec transform(Bento.Parser.t(), opts()) :: t()

Transform a parsed value into a struct.

defmodule User do
  defstruct name: "John", age: 27
end

Bento.Decoder.transform(%{"name" => "Bob"}, as: %User{})
# %User{name: "Bob", age: 27}