Description
Hello opening this issue because I've seen an unexpected behavior and want to discuss about it and see what's the best pattern
Given the following message:
message MyMessage {
String pkid = 1;
}
If I set a number field into pkid, I'm able to retrieve it correctly. Once I serialize and then deserialize the message, the value gets coerced as an empty string:
> protoConfig.setPkid(123);
> protoConfig.getPkid();
123
> MyMessage.deserializeBinary((protoConfig.serializeBinary())).getPkid()
""
I wasn't expecting the field to be transformed silently once the message is serialized. What I would expect from order of preference:
- Setting the field with
setPkid
to crash (or a warning) because the type is not what was expected - Serialization crashing (or a warning) because the type is not expected
- Coercing the type using
toString
which would set it to '123'
I understand suggested behaviors may have performance implications but I'm not sure what's the reason of current behavior because this still forces the user to do type checks before setting fields in a protobuf message when using javascript? IMO silently changing the value of a field when serializing a message is dangerous and I would aim for correctness of data first.