Open aslakhellesoy opened 4 years ago
Please hold off on merging this while I fix the failing tests. I'm also adding a bugfixes for enum fields and JSON.
With this change, bytes
values have to be encoded as Encoding::ASCII_8BIT
, which in Ruby means "binary" encoding. Any other encoding will cause the value to be Base64 decoded.
This is because the JSON representation of bytes
is always Base64. When deserialising JSON we don't have the protobuf field info, so the decoding is (unfortunately) happening inside Protobuf::Field::BytesField
, based on whether the value is a "binary" string or a "base64" string.
This PR adds a new
Message.from_json
class method that turns a JSON string into a message object.It addresses three shortcomings:
fooBarZap
) in the JSON are converted to underscore (fooBarZap
)bytes
fields are Base64 decoded unless they are already in "binary" format. This is because Protobuf's JSON representation uses Base64 encoding for bytes fields.