cmd/protoc-gen-go: use Merge instead of Marshal/Unmarshal

Change-Id: I689dee8417944bb0fbe19c75b7ca1accb49afb33
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/185144
Reviewed-by: Herbie Ong <herbie@google.com>
This commit is contained in:
Joe Tsai 2019-07-08 11:33:50 -07:00 committed by Joe Tsai
parent a804450cf6
commit 8b0b71e9b6

View File

@ -183,21 +183,11 @@ func genReflectFileDescriptor(gen *protogen.Plugin, g *protogen.GeneratedFile, f
}
func genFileDescriptor(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo) {
// TODO: Replace this with v2 Clone.
descProto := new(descriptorpb.FileDescriptorProto)
b, err := proto.Marshal(f.Proto)
if err != nil {
gen.Error(err)
return
}
if err := proto.Unmarshal(b, descProto); err != nil {
gen.Error(err)
return
}
proto.Merge(descProto, f.Proto)
descProto.SourceCodeInfo = nil // drop source code information
// Trim the source_code_info from the descriptor.
descProto.SourceCodeInfo = nil
b, err = proto.MarshalOptions{Deterministic: true}.Marshal(descProto)
b, err := proto.MarshalOptions{AllowPartial: true, Deterministic: true}.Marshal(descProto)
if err != nil {
gen.Error(err)
return