diff --git a/CHANGELOG.md b/CHANGELOG.md index 934647a..5de7e0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +# 0.2.1 +* Improve typespecs to allow for integers as a valid value to encode in RLP. # 0.2.0 * Breaking: added option to encode RLP to either hex strings (`"8055FF"`) or binaries (`<<0x80, 0x55, 0xFF>`). The default is now `:binary`. * Added typespecs and additional test coverage through doctests. diff --git a/lib/ex_rlp.ex b/lib/ex_rlp.ex index 2a51ded..ffe9fe7 100644 --- a/lib/ex_rlp.ex +++ b/lib/ex_rlp.ex @@ -3,7 +3,7 @@ defmodule ExRLP do @moduledoc File.read!("#{__DIR__}/../README.md") - @type t :: nil | [t] | binary() + @type t :: nil | binary() | integer() | [t] @doc """ Given an RLP structure, returns the encoding as a string. @@ -49,6 +49,7 @@ defmodule ExRLP do iex> ExRLP.encode(for _ <- 1..60, do: []) <<248, 60, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192>> """ + @spec encode(t) :: binary() @spec encode(t, keyword()) :: binary() def encode(item, options \\ []) do item |> Encoder.encode(options) @@ -98,6 +99,8 @@ defmodule ExRLP do iex> ExRLP.decode(<<143, 2, 227, 142, 158, 4, 75, 160, 83, 84, 85, 150, 0, 0, 0, 0>>) |> :binary.decode_unsigned 15_000_000_000_000_000_000_000_000_000_000_000 """ + @spec decode(binary()) :: t + @spec decode(binary(), atom()) :: t @spec decode(binary(), atom(), keyword()) :: t def decode(item, type \\ :binary, options \\ []) do item |> Decoder.decode(type, options) diff --git a/mix.exs b/mix.exs index 06582e2..3a16bd5 100644 --- a/mix.exs +++ b/mix.exs @@ -3,7 +3,7 @@ defmodule ExRLP.Mixfile do def project do [app: :ex_rlp, - version: "0.2.0", + version: "0.2.1", elixir: "~> 1.4", description: "Ethereum's Recursive Length Prefix (RLP) encoding", package: [