rust-protobuf
rust-protobuf copied to clipboard
Implement Oneof::descriptor in generated code
Will this allow doing
msg.subOneOfMsg.descriptor().get_name()
?
That operation would be not very useful: you already know what is descriptor name.
This would be useful in reflection (e.g. find all oneofs of a &dyn MessageDyn) and print their names.
Our usecase is to serialize the enum's name to relational database in a manner similar to internally tagged enums and store it as a separate column
@esseswann it should be possible now already, just with oneof descriptor it should be a little more convenient. Can you please describe, e.g. if you have
message Foo {
int32 bar = 1;
oneof baz {
string qux = 2;
bool quux = 3;
}
}
// and the protobuf message
bar: 1
qux: "test"
how it should be serialized to the database?
create table foos {
bar integer,
baz_type text,
baz_value jsonb
};
insert into foos(bar, baz_type, baz_value) values(1, 'qux', 'test');
This way one can achieve proper indexing by baz_type and compensate lack of polymorphism in relational databases by using json field for arbitrary data
I have created code example for your use case https://github.com/stepancheg/rust-protobuf/commit/f96a00c0a49ddb0a52116b633d28b2e25995edc6
Perfect, thank you so much