Decoding protobuf message with a oneof field

I’m using gogo protobuf to generate structs and one of them uses a oneOf, for example:

message Foo {
  oneof bar {
    Baz baz = 1;
    Qux qux = 2;
  } 
}

message Baz {}
message Qux {}

The mongo-go-driver correctly encodes and stores it in a collection. However when I need to fetch the value from mongo the driver fails with “error decoding key request: no decoder found for v1.isFoo_Bar”. This is because v1.isFoo_Bar is an interface. Is this use-case supported by the mongo-go-driver?

If not, is the only solution to this to write my own decoder?

I was able to workaround this by going from protobuf <=> json bytes <=> bson

I have the same problem, can you explain in detail how you solved it.


I try to use your solution, it works.
But the protojson can’t use proto tag, I must modify the message filed name.
Do you have any ideas for this.

Any more updates here? I have the same issue.