I have a basic protobuf message defined:
syntax = "proto3";
message Order {
string id = 1;
oneof placedby {
string customer_id = 2;
string store_id = 3;
}
}
I'm using kafka to create an event driven system, so when this event is picked up by the kafka consumer, I unmarshal the message, but the placed_by
field is always nil.
I'm setting it in a service like so:
newOrder := &Order{
Id: "123456789",
Placedby: &Order_CustomerId{ CustomerId: "987654321" },
}
out, err := proto.Marshal(newOrder)
if err != nil {
return err
}
At this point the event (out
) is broadcast and picked up by a consumer which unmarshals it:
order := &Order{}
err := proto.Unmarshal(event, order)
if err != nil {
return err
}
For some reason, the order.Placedby
field is always nil. The examples I've been able to find that marshal/unmarshal oneof field types are dealing with files: https://software-factotum.medium.com/protobuf-and-go-handling-oneof-field-type-172ca780ec47
Is there a known limitation for oneof fields when working with an event driven system? I'm using the "google.golang.org/protobuf/proto"
package version 1.28.0