proto: move T->*T wrappers from internal/scalar to proto
Usage of these is pervasive in code which works with proto2, and proto2
will be with us for a long, long time to come. Move them to the proto
package.
Change-Id: I1b2e57429fd5a8f107a848a4492d20c27f304bd7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/185543
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/compiler/protogen/protogen.go b/compiler/protogen/protogen.go
index 0191e09..6f6be12 100644
--- a/compiler/protogen/protogen.go
+++ b/compiler/protogen/protogen.go
@@ -30,7 +30,6 @@
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/fieldnum"
- "google.golang.org/protobuf/internal/scalar"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoreflect"
@@ -340,7 +339,7 @@
func (gen *Plugin) Response() *pluginpb.CodeGeneratorResponse {
resp := &pluginpb.CodeGeneratorResponse{}
if gen.err != nil {
- resp.Error = scalar.String(gen.err.Error())
+ resp.Error = proto.String(gen.err.Error())
return resp
}
for _, g := range gen.genFiles {
@@ -350,23 +349,23 @@
content, err := g.Content()
if err != nil {
return &pluginpb.CodeGeneratorResponse{
- Error: scalar.String(err.Error()),
+ Error: proto.String(err.Error()),
}
}
resp.File = append(resp.File, &pluginpb.CodeGeneratorResponse_File{
- Name: scalar.String(g.filename),
- Content: scalar.String(string(content)),
+ Name: proto.String(g.filename),
+ Content: proto.String(string(content)),
})
if gen.annotateCode && strings.HasSuffix(g.filename, ".go") {
meta, err := g.metaFile(content)
if err != nil {
return &pluginpb.CodeGeneratorResponse{
- Error: scalar.String(err.Error()),
+ Error: proto.String(err.Error()),
}
}
resp.File = append(resp.File, &pluginpb.CodeGeneratorResponse_File{
- Name: scalar.String(g.filename + ".meta"),
- Content: scalar.String(meta),
+ Name: proto.String(g.filename + ".meta"),
+ Content: proto.String(meta),
})
}
}
@@ -1061,10 +1060,10 @@
seenAnnotations[s] = true
for _, loc := range g.annotations[s] {
info.Annotation = append(info.Annotation, &descriptorpb.GeneratedCodeInfo_Annotation{
- SourceFile: scalar.String(loc.SourceFile),
+ SourceFile: proto.String(loc.SourceFile),
Path: loc.Path,
- Begin: scalar.Int32(int32(fset.Position(ident.Pos()).Offset)),
- End: scalar.Int32(int32(fset.Position(ident.End()).Offset)),
+ Begin: proto.Int32(int32(fset.Position(ident.Pos()).Offset)),
+ End: proto.Int32(int32(fset.Position(ident.End()).Offset)),
})
}
}
diff --git a/compiler/protogen/protogen_test.go b/compiler/protogen/protogen_test.go
index 2eb82ea..4604ed1 100644
--- a/compiler/protogen/protogen_test.go
+++ b/compiler/protogen/protogen_test.go
@@ -10,7 +10,7 @@
"testing"
"github.com/google/go-cmp/cmp"
- "google.golang.org/protobuf/internal/scalar"
+ "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/descriptorpb"
@@ -25,7 +25,7 @@
}
const params = "integer=2"
_, err := New(&pluginpb.CodeGeneratorRequest{
- Parameter: scalar.String(params),
+ Parameter: proto.String(params),
}, opts)
if err != nil {
t.Errorf("New(generator parameters %q): %v", params, err)
@@ -46,7 +46,7 @@
ParamFunc: flags.Set,
}
_, err := New(&pluginpb.CodeGeneratorRequest{
- Parameter: scalar.String(parameter),
+ Parameter: proto.String(parameter),
}, opts)
if err == nil {
t.Errorf("New(generator parameters %q): want error, got nil", parameter)
@@ -58,14 +58,14 @@
gen, err := New(&pluginpb.CodeGeneratorRequest{
ProtoFile: []*descriptorpb.FileDescriptorProto{
{
- Name: scalar.String("testdata/go_package/no_go_package.proto"),
- Syntax: scalar.String(protoreflect.Proto3.String()),
- Package: scalar.String("goproto.testdata"),
+ Name: proto.String("testdata/go_package/no_go_package.proto"),
+ Syntax: proto.String(protoreflect.Proto3.String()),
+ Package: proto.String("goproto.testdata"),
},
{
- Name: scalar.String("testdata/go_package/no_go_package_import.proto"),
- Syntax: scalar.String(protoreflect.Proto3.String()),
- Package: scalar.String("goproto.testdata"),
+ Name: proto.String("testdata/go_package/no_go_package_import.proto"),
+ Syntax: proto.String(protoreflect.Proto3.String()),
+ Package: proto.String("goproto.testdata"),
Dependency: []string{"go_package/no_go_package.proto"},
},
},
@@ -167,13 +167,13 @@
test.desc, test.parameter, filename, test.generate, test.goPackageOption)
req := &pluginpb.CodeGeneratorRequest{
- Parameter: scalar.String(test.parameter),
+ Parameter: proto.String(test.parameter),
ProtoFile: []*descriptorpb.FileDescriptorProto{
{
- Name: scalar.String(filename),
- Package: scalar.String(protoPackageName),
+ Name: proto.String(filename),
+ Package: proto.String(protoPackageName),
Options: &descriptorpb.FileOptions{
- GoPackage: scalar.String(test.goPackageOption),
+ GoPackage: proto.String(test.goPackageOption),
},
},
},
@@ -207,14 +207,14 @@
gen, err := New(&pluginpb.CodeGeneratorRequest{
ProtoFile: []*descriptorpb.FileDescriptorProto{
{
- Name: scalar.String("dir/file1.proto"),
- Package: scalar.String("proto.package"),
+ Name: proto.String("dir/file1.proto"),
+ Package: proto.String("proto.package"),
},
{
- Name: scalar.String("dir/file2.proto"),
- Package: scalar.String("proto.package"),
+ Name: proto.String("dir/file2.proto"),
+ Package: proto.String("proto.package"),
Options: &descriptorpb.FileOptions{
- GoPackage: scalar.String("foo"),
+ GoPackage: proto.String("foo"),
},
},
},
@@ -234,17 +234,17 @@
_, err := New(&pluginpb.CodeGeneratorRequest{
ProtoFile: []*descriptorpb.FileDescriptorProto{
{
- Name: scalar.String("dir/file1.proto"),
- Package: scalar.String("proto.package"),
+ Name: proto.String("dir/file1.proto"),
+ Package: proto.String("proto.package"),
Options: &descriptorpb.FileOptions{
- GoPackage: scalar.String("golang.org/x/foo"),
+ GoPackage: proto.String("golang.org/x/foo"),
},
},
{
- Name: scalar.String("dir/file2.proto"),
- Package: scalar.String("proto.package"),
+ Name: proto.String("dir/file2.proto"),
+ Package: proto.String("proto.package"),
Options: &descriptorpb.FileOptions{
- GoPackage: scalar.String("golang.org/x/foo;bar"),
+ GoPackage: proto.String("golang.org/x/foo;bar"),
},
},
},