According to this issue, the protoreflect package provides APIs for accessing the "unknown fields" of protobuf messages, but I don't see any way to use it if there isn't any existing schema. Basically, I want to perform a "weak decode", similar to what the JSON unmarshaller does if the output is of type map[string]interface{}
.
The example from the documentation looks like this:
err := UnmarshalOptions{DiscardUnknown: true}.Unmarshal(b, m)
where b
is the input byte slice and m
is the output message, which needs to be initialised somehow, as you can see here. I was thinking that dynamicpb can be used for this purpose, but it doesn't look possible without having an existing MessageDescriptor and that's where I got stuck...
Aucun commentaire:
Enregistrer un commentaire