davisp / jiffy

JSON NIFs for Erlang
Other
869 stars 319 forks source link

bytes_per_red option returns badarg #204

Closed lpgauth closed 4 years ago

lpgauth commented 4 years ago

Hi, Wanted to play around with bytes_per_red option to see the effect but I keep getting a badarg.

jiffy:decode(<<"{\"test\":\"foo\"}">>, [{bytes_per_red, 20}]).
** exception error: bad argument
     in function  jiffy:nif_decode_init/2
        called as jiffy:nif_decode_init(<<"{\"test\":\"foo\"}">>,[{bytes_per_red,20}])
     in call from jiffy:decode/2 (/app/_build/default/lib/jiffy/src/jiffy.erl, line 69)
davisp commented 4 years ago

That's been changed to bytes_per_iter and has roughly the same meaning. If memory serves bytes_per_red would calculate 2000 * $bytes_per_red and yield after it'd generated or consumed that many bytes. The new approach is just a straight up how many bytes as it seemed less awkward for users to control.

lpgauth commented 4 years ago

Hi @davisp, thanks for the quick reply.

From the README:

{bytes_per_iter, N} where N >= 0 - Backwards compatible option that is converted into the bytes_per_red value.

From this I assumed bytes_per_iter was deprecated and bytes_per_red should be used. Also, from the specs it's still a valid option... maybe it should be removed?

davisp commented 4 years ago

Huh, that was mostly from memory and I apparently managed to get it completely backwards. Now that I look closer there's definitely a silly bug when grabbing the bytes_per_red option. Its fixed in Jiffy 1.0.6 which has been uploaded to hex.