bitwalker / exprotobuf

Protocol Buffers in Elixir made easy!
Apache License 2.0
486 stars 69 forks source link

Run verify_msg before encoding #116

Open luisguilhermemsalmeida opened 1 year ago

luisguilhermemsalmeida commented 1 year ago

Encoding integer values of out the specified range (overflow) results in an invalid binary which crashes the decoding in a way that is very hard to troubleshoot. It's best if the encoding fails with an easy message:

** (ErlangError) Erlang error: {:gpb_type_error, {{:value_out_of_range, :unsigned, 32}, [value: 340282366920938463463374607431768211456, path: 'path_to_the_invalid_field']}}

https://github.com/tomas-abrahamsson/gpb README file states:

Gpb can optionally generate code for verification of values during encoding this makes it easy to catch e.g integers out of range, or values of the wrong type.

luisguilhermemsalmeida commented 1 year ago

@bitwalker Did you have the time to take a look at this PR? Thanks!