Closed edam closed 4 years ago
When the use_default_metatable option is used, values for oneof fields are returned even when they are not present.
use_default_metatable
oneof
For example,
syntax = "proto3"; message Foo { oneof optional_a { int32 a = 1; } oneof test { int32 b = 2; int32 c = 3; } }
Decoding works:
lua> pb.option( "use_default_metatable" ) lua> local foo = pb.encode( 'Foo', { b = 9 } ) lua> dump( foo ) { b = 9 } lua> foo.b 9
However, accessing fields via the metatable yields default values for oneof fields that are not present.
lua> foo.a 0 lua> foo.c 0
These previous results should be nil, because they are not present in the oneof.
nil
(Note: the use_default_values option works ok. It's just the metatable defaults that are wrong.)
use_default_values
metatale doesn't know the oneof, it used for custom default values (you have chance to set your own metatale), so in your case just don't use it :-)
When the
use_default_metatable
option is used, values foroneof
fields are returned even when they are not present.For example,
Decoding works:
However, accessing fields via the metatable yields default values for
oneof
fields that are not present.These previous results should be
nil
, because they are not present in theoneof
.(Note: the
use_default_values
option works ok. It's just the metatable defaults that are wrong.)