You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to include type info of a proto message by creating a wrapper message that includes a google.protobuf.DescriptorProto field. However, when I call .ProtoReflect().Descriptor() on the *descriptorpb.DescriptorProto field, all the info is lost. I believe this is due to the descriptor.proto file having outdated "proto2" syntax. Here is how I tested this:
Create a test .proto file.
syntax = "proto3";
package project;
option go_package = ".;project";
message Test {
string data = 1;
}
Generate the .pb.go file with protoc. (I used protoc -I=. --go_out=. ./test.proto)
Write a test file:
import (
"fmt"
reflect "reflect"
"testing"
"google.golang.org/protobuf/reflect/protodesc"
)
func TestDesc(t *testing.T) {
data := &Test{
Data: "hi",
}
prMessage := data.ProtoReflect() //protoreflect.Message
msgDesc := prMessage.Descriptor() //protoreflect MessageDescriptor
fmt.Println("msgDesc ", msgDesc)
descProto := protodesc.ToDescriptorProto(msgDesc) //converts from protoreflect.MessageDescriptor to *descriptorpb.DescriptorProto
prMessage2 := descProto.ProtoReflect() //protoreflect.Message
msgDesc2 := prMessage2.Descriptor() //protoreflect MessageDescriptor
fmt.Println("msgDesc2 ", msgDesc2)
if !reflect.DeepEqual(msgDesc, msgDesc2) {
t.Errorf("(%s) does not match (%s)", msgDesc, msgDesc2)
}
}
What did you expect to see?
I expected to get back the MessageDescriptor (so msgDesc and msgDesc2 should match)
This is a protocol buffer question, and therefore more appropriate to github.com/golang/protobuf. Or actually, since it's about descriptor.proto, github.com/protocolbuffers/protobuf.
This also has nothing to do with proto2 vs. proto3.
The result you're seeing is because msgDesc is the descriptor of the Test message type, and msgDesc2 is the descriptor of the google.protobuf.DescriptorProto message type. You can easily see this if you compare the FullName of each descriptor.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I wanted to include type info of a proto message by creating a wrapper message that includes a
google.protobuf.DescriptorProto
field. However, when I call.ProtoReflect().Descriptor()
on the*descriptorpb.DescriptorProto
field, all the info is lost. I believe this is due to the descriptor.proto file having outdated "proto2" syntax. Here is how I tested this:.proto
file..pb.go
file withprotoc
. (I usedprotoc -I=. --go_out=. ./test.proto
)What did you expect to see?
I expected to get back the MessageDescriptor (so
msgDesc
andmsgDesc2
should match)What did you see instead?
msgDesc2
has syntax proto2 instead of proto3 and loses all the info from the MessageDescriptor.The text was updated successfully, but these errors were encountered: