Open aiotter opened 3 days ago
Hello @aiotter
Thank you for your interest in AtomVM. I will let @bettio chime in, but I believe an implementation of binary:encode_hex/1
and binary:decode_hex/1
(and maybe binary:encode_hex/2
) would be welcome, especially if it matches our contribution rules (licensing, coding style), and it would likely be approved it if it comes with docs and specs in binary.erl module and tests that also pass with BEAM.
I guess that a nif would be more memory efficient than a binary comprehension, but the following seems to work with AtomVM. We certainly don't need something as complex as Erlang/OTP's implementation.
encode_hex(B) ->
<< << (hd(integer_to_list(X, 16))):8 >> || <<X:4>> <= B >>.
Indeed, we are looking forward to any contribution about this.
@pguyot @bettio Thank you for your reply!
I was shocked to see your beautifully simple code. I implemented the function in Elixir firstly, but my implementation is not elegant as yours. Actually I'm not used to Erlang or Elixir very much. Just like half a year using them.
After I created this issue, I took a research and found that the reason why my code being too slow is because I print every parsed result, not because of my Elixir implementation. So now I think Nifs are not needed for this kind of trivial tasks.
dump(binary()) :: charlist()
, if you are interested.Anyway, I'm willing to submit a PR which implements binary:encode_hex/1
, binary:decode_hex/1
and binary:encode_hex/2
in Erlang after my current task is completed.
They must be helpful for people like us when dumping some data from microcontrollers to send them into Wireshark.
There are lots of lacking functions like string:pad
(String.pad_leading
) and (implemented at dfe2003ad1e42ea2d23adf944e55e0c926e72685). I needed to implement them by myself. Do you also accept PRs for implementing them?
I want to know what kind of functions are needed in binary:copy
eavmlib
and exavmlib
, if there are something like general rules. I know you don't want every function in OTP.
Thank you very much.
We are glad to receive any kind of contribution, including string:pad
or anything else.
There will be some comments and feedback before merging a pull request in order to make sure the contribution matches our contribution rules, such as tests coding style and etc...
So if it is ok for you to go through the review process, please open a pull request and we'll do our best to review it.
I'm an engineer working at @realglobe-Inc. We use AtomVM to develop Wi-Fi sniffer on ESP-32.
We need to get a fast implementation for dumping Wi-Fi frame packet into hexadecimal string. So we made Nifs to dump and load hexadecimal string, which is very much similar to
binary:encode_hex/1
andbinary:decode_hex/1
. I think I can add small codes and fit them intosrc/libAtomVM/nifs.c
with a little effort. Do I have a chance to get it merged if I create a PR?Maybe we can create
Base.encode16
andBase.decode16
as well. AlsoBase.encode64
andBase.decode64
with already implementedbase64:encode
andbase64:decode
.