Skip to content

Commit

Permalink
Update common tests (#52)
Browse files Browse the repository at this point in the history
This pr simplifies decoding logic. The code has worse performance but
better maintainability
  • Loading branch information
ayrat555 authored Feb 23, 2023
1 parent fefe60f commit 60b8fe6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1,480 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 25.0.2
elixir 1.14.0-otp-25
elixir 1.14.3-otp-25
2 changes: 1 addition & 1 deletion lib/ex_rlp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ defmodule ExRLP do
## Examples
iex> ExRLP.decode(<<>>)
nil
** (ExRLP.DecodeError) invalid rlp encoding
iex> ExRLP.decode(<<0x83, ?d, ?o, ?g>>)
"dog"
Expand Down
6 changes: 5 additions & 1 deletion lib/ex_rlp/decode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ defmodule ExRLP.Decode do

alias ExRLP.DecodeItem
@spec decode(binary(), keyword()) :: ExRLP.t()
def decode(item, options \\ []) when is_binary(item) do
def decode(item, options \\ [])

def decode("", _), do: raise(ExRLP.DecodeError)

def decode(item, options) when is_binary(item) do
item
|> unencode(Keyword.get(options, :encoding, :binary))
|> DecodeItem.decode_item()
Expand Down
Loading

0 comments on commit 60b8fe6

Please sign in to comment.