Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why :error when data is not binary? #14

Closed
nelsonic opened this issue Apr 25, 2020 · 3 comments
Closed

Why :error when data is not binary? #14

nelsonic opened this issue Apr 25, 2020 · 3 comments
Assignees
Labels

Comments

@nelsonic
Copy link
Member

At present when the value to be encoded is not a binary, we return an :error:
https://github.com/dwyl/exbase58/blob/c56a72407fa6f8b09423d9461206fafec68bc809/lib/base58encode.ex#L32-L33

Why? 🤷

@nelsonic nelsonic added question Further information is requested technical discuss labels Apr 25, 2020
@nelsonic
Copy link
Member Author

nelsonic commented Apr 25, 2020

We don't need throw :error if it's not a requirement. 💭
We can simply convert any value (Number, Atom, etc.) to Binary before encoding:

 def encode(anything) do
   :erlang.term_to_binary(anything)
   |> encode()
 end

see: https://elixirforum.com/t/erlang-term-to-binary-and-vice-versa-in-elixir/11034/3

@nelsonic
Copy link
Member Author

I need to encode Integer values for dwyl/auth#49 so I've added the code and tests to #17

@nelsonic
Copy link
Member Author

The code is backwards compatible provided people weren't counting on getting an :error.
Closing. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants