You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When initializing a protobuf message object with a hash of attributes, is it possible to fail if an attribute is not a field on the underlying message?
classFoo < Protobuf::Messageoptional:string,:hello,1end# This is normal useFoo.new(:hello=>"world")# This could fail with an UnknownAttributeError, but does notFoo.new(:some_random_attribute_that_doesnt_exist=>"foobar")
The text was updated successfully, but these errors were encountered:
Unsure if you're asking a question or proposing a change...
No, we don't fail when you provide a bogus field on hash initialization. When decoding bytes we don't fail on unknown fields (for obvious reasons) and I believe that behavior has transferred over to initialization with a hash.
Not sure if we should "fail"; I looked through the Java and C implementations and it looks like they store unknown attributes (fields) in a map (UnknownFieldSet in C, FieldSet in Java) and allow introspection on the fields that are unknown through methods like is_empty?(), field_count()
if those implementation don't blow-up when unknown fields are encountered then it seems we should follow that path
they do not however generate the assignment methods to assign the value, but during initialization it doesn't look like they stop execution
When initializing a protobuf message object with a hash of attributes, is it possible to fail if an attribute is not a field on the underlying message?
The text was updated successfully, but these errors were encountered: