internal/scalar: add scalar package for primitive wrappers
Add the scalar package to reduce dependencies on the v1 proto runtime package.
It may very well be the case that these functions should be exposed in the
public API of v2, but that is not a decision we need to make now.
Change-Id: Ifbc6d15311ba5837909ac72af47c630a80a142ef
Reviewed-on: https://go-review.googlesource.com/c/151402
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/cmd/protoc-gen-go/golden_test.go b/cmd/protoc-gen-go/golden_test.go
index 7646716..3ee0cc0 100644
--- a/cmd/protoc-gen-go/golden_test.go
+++ b/cmd/protoc-gen-go/golden_test.go
@@ -17,6 +17,7 @@
"github.com/golang/protobuf/proto"
descpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/golang/protobuf/v2/internal/protogen/goldentest"
+ "github.com/golang/protobuf/v2/internal/scalar"
)
// Set --regenerate to regenerate the golden files.
@@ -81,9 +82,9 @@
end := begin + len(want.text)
wantInfo.Annotation = append(wantInfo.Annotation, &descpb.GeneratedCodeInfo_Annotation{
Path: want.path,
- Begin: proto.Int32(int32(begin)),
- End: proto.Int32(int32(end)),
- SourceFile: proto.String("annotations.proto"),
+ Begin: scalar.Int32(int32(begin)),
+ End: scalar.Int32(int32(end)),
+ SourceFile: scalar.String("annotations.proto"),
})
}
if !proto.Equal(gotInfo, wantInfo) {
diff --git a/internal/cmd/pbdump/pbdump.go b/internal/cmd/pbdump/pbdump.go
index ec65a55..0e422f0 100644
--- a/internal/cmd/pbdump/pbdump.go
+++ b/internal/cmd/pbdump/pbdump.go
@@ -17,10 +17,10 @@
"strconv"
"strings"
- protoV1 "github.com/golang/protobuf/proto"
descriptorV1 "github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/golang/protobuf/v2/internal/encoding/pack"
"github.com/golang/protobuf/v2/internal/encoding/wire"
+ "github.com/golang/protobuf/v2/internal/scalar"
"github.com/golang/protobuf/v2/reflect/protoreflect"
"github.com/golang/protobuf/v2/reflect/prototype"
)
@@ -229,7 +229,7 @@
protoreflect.Sfixed32Kind, protoreflect.Fixed32Kind, protoreflect.FloatKind,
protoreflect.Sfixed64Kind, protoreflect.Fixed64Kind, protoreflect.DoubleKind:
f.Cardinality = protoreflect.Repeated
- f.Options = &descriptorV1.FieldOptions{Packed: protoV1.Bool(true)}
+ f.Options = &descriptorV1.FieldOptions{Packed: scalar.Bool(true)}
case protoreflect.MessageKind, protoreflect.GroupKind:
s := name.Append(protoreflect.Name(fmt.Sprintf("M%d", n)))
f.MessageType = prototype.PlaceholderMessage(s)
diff --git a/internal/encoding/tag/tag.go b/internal/encoding/tag/tag.go
index 17e0aca..3c9765c 100644
--- a/internal/encoding/tag/tag.go
+++ b/internal/encoding/tag/tag.go
@@ -13,9 +13,9 @@
"strconv"
"strings"
- protoV1 "github.com/golang/protobuf/proto"
descriptorV1 "github.com/golang/protobuf/protoc-gen-go/descriptor"
ptext "github.com/golang/protobuf/v2/internal/encoding/text"
+ scalar "github.com/golang/protobuf/v2/internal/scalar"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
)
@@ -105,9 +105,9 @@
case strings.HasPrefix(s, "json="):
f.JSONName = s[len("json="):]
case s == "packed":
- f.Options.Packed = protoV1.Bool(true)
+ f.Options.Packed = scalar.Bool(true)
case strings.HasPrefix(s, "weak="):
- f.Options.Weak = protoV1.Bool(true)
+ f.Options.Weak = scalar.Bool(true)
f.MessageType = ptype.PlaceholderMessage(pref.FullName(s[len("weak="):]))
case strings.HasPrefix(s, "def="):
// The default tag is special in that everything afterwards is the
diff --git a/internal/impl/legacy_message.go b/internal/impl/legacy_message.go
index 4b64359..440b283 100644
--- a/internal/impl/legacy_message.go
+++ b/internal/impl/legacy_message.go
@@ -11,9 +11,9 @@
"sync"
"unicode"
- protoV1 "github.com/golang/protobuf/proto"
descriptorV1 "github.com/golang/protobuf/protoc-gen-go/descriptor"
ptag "github.com/golang/protobuf/v2/internal/encoding/tag"
+ scalar "github.com/golang/protobuf/v2/internal/scalar"
pvalue "github.com/golang/protobuf/v2/internal/value"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
@@ -253,7 +253,7 @@
m := &ptype.StandaloneMessage{
Syntax: parent.Syntax,
FullName: parent.FullName.Append(mapEntryName(f.Name)),
- Options: &descriptorV1.MessageOptions{MapEntry: protoV1.Bool(true)},
+ Options: &descriptorV1.MessageOptions{MapEntry: scalar.Bool(true)},
Fields: []ptype.Field{
ms.parseField(tagKey, "", "", t.Key(), nil),
ms.parseField(tagVal, "", "", t.Elem(), nil),
diff --git a/internal/impl/legacy_test.go b/internal/impl/legacy_test.go
index 2333fc5..71b4db2 100644
--- a/internal/impl/legacy_test.go
+++ b/internal/impl/legacy_test.go
@@ -13,6 +13,7 @@
protoV1 "github.com/golang/protobuf/proto"
pack "github.com/golang/protobuf/v2/internal/encoding/pack"
pragma "github.com/golang/protobuf/v2/internal/pragma"
+ scalar "github.com/golang/protobuf/v2/internal/scalar"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
cmp "github.com/google/go-cmp/cmp"
@@ -848,8 +849,8 @@
}
// Set some values and append to values to the lists.
- m1a := &proto2_20180125.Message_ChildMessage{F1: protoV1.String("m1a")}
- m1b := &proto2_20180125.Message_ChildMessage{F1: protoV1.String("m2b")}
+ m1a := &proto2_20180125.Message_ChildMessage{F1: scalar.String("m1a")}
+ m1b := &proto2_20180125.Message_ChildMessage{F1: scalar.String("m2b")}
m2a := &EnumMessages{EnumP2: EnumProto2(0x1b).Enum()}
m2b := &EnumMessages{EnumP2: EnumProto2(0x2b).Enum()}
setValues := []interface{}{
diff --git a/internal/impl/message_test.go b/internal/impl/message_test.go
index 999bdd6..5637b92 100644
--- a/internal/impl/message_test.go
+++ b/internal/impl/message_test.go
@@ -12,6 +12,7 @@
protoV1 "github.com/golang/protobuf/proto"
descriptorV1 "github.com/golang/protobuf/protoc-gen-go/descriptor"
+ scalar "github.com/golang/protobuf/v2/internal/scalar"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
cmp "github.com/google/go-cmp/cmp"
@@ -559,7 +560,7 @@
{Name: "key", Number: 1, Cardinality: pref.Optional, Kind: keyKind},
{Name: "value", Number: 2, Cardinality: pref.Optional, Kind: valKind},
},
- Options: &descriptorV1.MessageOptions{MapEntry: protoV1.Bool(true)},
+ Options: &descriptorV1.MessageOptions{MapEntry: scalar.Bool(true)},
}),
}
}
@@ -964,7 +965,7 @@
{Name: "key", Number: 1, Cardinality: pref.Optional, Kind: pref.StringKind},
{Name: "value", Number: 2, Cardinality: pref.Optional, Kind: pref.EnumKind, EnumType: enumProto3Type},
},
- Options: &descriptorV1.MessageOptions{MapEntry: protoV1.Bool(true)},
+ Options: &descriptorV1.MessageOptions{MapEntry: scalar.Bool(true)},
})
var messageMapDesc = mustMakeMessageDesc(ptype.StandaloneMessage{
@@ -974,7 +975,7 @@
{Name: "key", Number: 1, Cardinality: pref.Optional, Kind: pref.StringKind},
{Name: "value", Number: 2, Cardinality: pref.Optional, Kind: pref.MessageKind, MessageType: scalarProto3Type.Type},
},
- Options: &descriptorV1.MessageOptions{MapEntry: protoV1.Bool(true)},
+ Options: &descriptorV1.MessageOptions{MapEntry: scalar.Bool(true)},
})
func (m *EnumMessages) Type() pref.MessageType { return enumMessagesType.Type }
@@ -1017,10 +1018,10 @@
func (*EnumMessages_OneofM3) isEnumMessages_Union() {}
func TestEnumMessages(t *testing.T) {
- wantL := MessageOf(&proto2_20180125.Message{OptionalFloat: protoV1.Float32(math.E)})
+ wantL := MessageOf(&proto2_20180125.Message{OptionalFloat: scalar.Float32(math.E)})
wantM := &EnumMessages{EnumP2: EnumProto2(1234).Enum()}
- wantM2a := &ScalarProto2{Float32: protoV1.Float32(math.Pi)}
- wantM2b := &ScalarProto2{Float32: protoV1.Float32(math.Phi)}
+ wantM2a := &ScalarProto2{Float32: scalar.Float32(math.Pi)}
+ wantM2b := &ScalarProto2{Float32: scalar.Float32(math.Phi)}
wantM3a := &ScalarProto3{Float32: math.Pi}
wantM3b := &ScalarProto3{Float32: math.Ln2}
@@ -1104,7 +1105,7 @@
equalMessage{&EnumMessages{
EnumP2: EnumProto2(0xdead).Enum(),
EnumP3: EnumProto3(0).Enum(),
- MessageLegacy: &proto2_20180125.Message{OptionalFloat: protoV1.Float32(math.E)},
+ MessageLegacy: &proto2_20180125.Message{OptionalFloat: scalar.Float32(math.E)},
MessageCycle: wantM,
MessageList: []*ScalarProto2{wantM2a, wantM2b},
EnumMap: map[string]EnumProto3{"one": 1, "two": 2},
diff --git a/internal/scalar/scalar.go b/internal/scalar/scalar.go
new file mode 100644
index 0000000..54f14af
--- /dev/null
+++ b/internal/scalar/scalar.go
@@ -0,0 +1,18 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package scalar provides wrappers for populating optional scalar fields.
+package scalar
+
+// TODO: Should this be public in the v2 API? Where should it live?
+// Would we want to do something different if Go gets generics?
+
+func Bool(v bool) *bool { return &v }
+func Int32(v int32) *int32 { return &v }
+func Int64(v int64) *int64 { return &v }
+func Uint32(v uint32) *uint32 { return &v }
+func Uint64(v uint64) *uint64 { return &v }
+func Float32(v float32) *float32 { return &v }
+func Float64(v float64) *float64 { return &v }
+func String(v string) *string { return &v }
diff --git a/protogen/protogen.go b/protogen/protogen.go
index 9be2d77..8951ca0 100644
--- a/protogen/protogen.go
+++ b/protogen/protogen.go
@@ -30,6 +30,7 @@
"github.com/golang/protobuf/proto"
descpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
pluginpb "github.com/golang/protobuf/protoc-gen-go/plugin"
+ "github.com/golang/protobuf/v2/internal/scalar"
"github.com/golang/protobuf/v2/reflect/protoreflect"
"github.com/golang/protobuf/v2/reflect/protoregistry"
"github.com/golang/protobuf/v2/reflect/prototype"
@@ -336,30 +337,30 @@
func (gen *Plugin) Response() *pluginpb.CodeGeneratorResponse {
resp := &pluginpb.CodeGeneratorResponse{}
if gen.err != nil {
- resp.Error = proto.String(gen.err.Error())
+ resp.Error = scalar.String(gen.err.Error())
return resp
}
for _, g := range gen.genFiles {
content, err := g.content()
if err != nil {
return &pluginpb.CodeGeneratorResponse{
- Error: proto.String(err.Error()),
+ Error: scalar.String(err.Error()),
}
}
resp.File = append(resp.File, &pluginpb.CodeGeneratorResponse_File{
- Name: proto.String(g.filename),
- Content: proto.String(string(content)),
+ Name: scalar.String(g.filename),
+ Content: scalar.String(string(content)),
})
if gen.annotateCode && strings.HasSuffix(g.filename, ".go") {
meta, err := g.metaFile(content)
if err != nil {
return &pluginpb.CodeGeneratorResponse{
- Error: proto.String(err.Error()),
+ Error: scalar.String(err.Error()),
}
}
resp.File = append(resp.File, &pluginpb.CodeGeneratorResponse_File{
- Name: proto.String(g.filename + ".meta"),
- Content: proto.String(meta),
+ Name: scalar.String(g.filename + ".meta"),
+ Content: scalar.String(meta),
})
}
}
@@ -994,10 +995,10 @@
seenAnnotations[s] = true
for _, loc := range g.annotations[s] {
info.Annotation = append(info.Annotation, &descpb.GeneratedCodeInfo_Annotation{
- SourceFile: proto.String(loc.SourceFile),
+ SourceFile: scalar.String(loc.SourceFile),
Path: loc.Path,
- Begin: proto.Int32(int32(fset.Position(ident.Pos()).Offset)),
- End: proto.Int32(int32(fset.Position(ident.End()).Offset)),
+ Begin: scalar.Int32(int32(fset.Position(ident.Pos()).Offset)),
+ End: scalar.Int32(int32(fset.Position(ident.End()).Offset)),
})
}
}
diff --git a/protogen/protogen_test.go b/protogen/protogen_test.go
index a61c18b..b098845 100644
--- a/protogen/protogen_test.go
+++ b/protogen/protogen_test.go
@@ -19,6 +19,7 @@
"github.com/golang/protobuf/proto"
descpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
pluginpb "github.com/golang/protobuf/protoc-gen-go/plugin"
+ "github.com/golang/protobuf/v2/internal/scalar"
)
func TestPluginParameters(t *testing.T) {
@@ -29,7 +30,7 @@
}
const params = "integer=2"
_, err := New(&pluginpb.CodeGeneratorRequest{
- Parameter: proto.String(params),
+ Parameter: scalar.String(params),
}, opts)
if err != nil {
t.Errorf("New(generator parameters %q): %v", params, err)
@@ -50,7 +51,7 @@
ParamFunc: flags.Set,
}
_, err := New(&pluginpb.CodeGeneratorRequest{
- Parameter: proto.String(parameter),
+ Parameter: scalar.String(parameter),
}, opts)
if err == nil {
t.Errorf("New(generator parameters %q): want error, got nil", parameter)
@@ -170,13 +171,13 @@
test.desc, test.parameter, filename, test.generate, test.goPackageOption)
req := &pluginpb.CodeGeneratorRequest{
- Parameter: proto.String(test.parameter),
+ Parameter: scalar.String(test.parameter),
ProtoFile: []*descpb.FileDescriptorProto{
{
- Name: proto.String(filename),
- Package: proto.String(protoPackageName),
+ Name: scalar.String(filename),
+ Package: scalar.String(protoPackageName),
Options: &descpb.FileOptions{
- GoPackage: proto.String(test.goPackageOption),
+ GoPackage: scalar.String(test.goPackageOption),
},
},
},
@@ -210,14 +211,14 @@
gen, err := New(&pluginpb.CodeGeneratorRequest{
ProtoFile: []*descpb.FileDescriptorProto{
{
- Name: proto.String("dir/file1.proto"),
- Package: proto.String("proto.package"),
+ Name: scalar.String("dir/file1.proto"),
+ Package: scalar.String("proto.package"),
},
{
- Name: proto.String("dir/file2.proto"),
- Package: proto.String("proto.package"),
+ Name: scalar.String("dir/file2.proto"),
+ Package: scalar.String("proto.package"),
Options: &descpb.FileOptions{
- GoPackage: proto.String("foo"),
+ GoPackage: scalar.String("foo"),
},
},
},
@@ -237,17 +238,17 @@
_, err := New(&pluginpb.CodeGeneratorRequest{
ProtoFile: []*descpb.FileDescriptorProto{
{
- Name: proto.String("dir/file1.proto"),
- Package: proto.String("proto.package"),
+ Name: scalar.String("dir/file1.proto"),
+ Package: scalar.String("proto.package"),
Options: &descpb.FileOptions{
- GoPackage: proto.String("golang.org/x/foo"),
+ GoPackage: scalar.String("golang.org/x/foo"),
},
},
{
- Name: proto.String("dir/file2.proto"),
- Package: proto.String("proto.package"),
+ Name: scalar.String("dir/file2.proto"),
+ Package: scalar.String("proto.package"),
Options: &descpb.FileOptions{
- GoPackage: proto.String("golang.org/x/foo;bar"),
+ GoPackage: scalar.String("golang.org/x/foo;bar"),
},
},
},
diff --git a/reflect/prototype/type_test.go b/reflect/prototype/type_test.go
index 93334d5..65e5d78 100644
--- a/reflect/prototype/type_test.go
+++ b/reflect/prototype/type_test.go
@@ -15,6 +15,7 @@
protoV1 "github.com/golang/protobuf/proto"
descriptorV1 "github.com/golang/protobuf/protoc-gen-go/descriptor"
+ scalar "github.com/golang/protobuf/v2/internal/scalar"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
)
@@ -113,17 +114,17 @@
Syntax: pref.Proto2,
Path: "path/to/file.proto",
Package: "test",
- Options: &descriptorV1.FileOptions{Deprecated: protoV1.Bool(true)},
+ Options: &descriptorV1.FileOptions{Deprecated: scalar.Bool(true)},
Messages: []Message{{
Name: "A", // "test.A"
Options: &descriptorV1.MessageOptions{
- MapEntry: protoV1.Bool(true),
- Deprecated: protoV1.Bool(true),
+ MapEntry: scalar.Bool(true),
+ Deprecated: scalar.Bool(true),
},
Fields: []Field{{
Name: "key", // "test.A.key"
Number: 1,
- Options: &descriptorV1.FieldOptions{Deprecated: protoV1.Bool(true)},
+ Options: &descriptorV1.FieldOptions{Deprecated: scalar.Bool(true)},
Cardinality: pref.Optional,
Kind: pref.StringKind,
}, {
@@ -170,7 +171,7 @@
Number: 5,
Cardinality: pref.Repeated,
Kind: pref.Int32Kind,
- Options: &descriptorV1.FieldOptions{Packed: protoV1.Bool(true)},
+ Options: &descriptorV1.FieldOptions{Packed: scalar.Bool(true)},
}, {
Name: "field_six", // "test.B.field_six"
Number: 6,
@@ -204,19 +205,19 @@
Number: 1000,
Cardinality: pref.Repeated,
Kind: pref.MessageKind,
- Options: &descriptorV1.FieldOptions{Packed: protoV1.Bool(false)},
+ Options: &descriptorV1.FieldOptions{Packed: scalar.Bool(false)},
MessageType: PlaceholderMessage("test.C"),
ExtendedType: PlaceholderMessage("test.B"),
}},
}},
Enums: []Enum{{
Name: "E1", // "test.E1"
- Options: &descriptorV1.EnumOptions{Deprecated: protoV1.Bool(true)},
+ Options: &descriptorV1.EnumOptions{Deprecated: scalar.Bool(true)},
Values: []EnumValue{
{
Name: "FOO",
Number: 0,
- Options: &descriptorV1.EnumValueOptions{Deprecated: protoV1.Bool(true)},
+ Options: &descriptorV1.EnumValueOptions{Deprecated: scalar.Bool(true)},
},
{Name: "BAR", Number: 1},
},
@@ -226,20 +227,20 @@
Number: 1000,
Cardinality: pref.Repeated,
Kind: pref.MessageKind,
- Options: &descriptorV1.FieldOptions{Packed: protoV1.Bool(true)},
+ Options: &descriptorV1.FieldOptions{Packed: scalar.Bool(true)},
MessageType: PlaceholderMessage("test.C"),
ExtendedType: PlaceholderMessage("test.B"),
}},
Services: []Service{{
Name: "S", // "test.S"
- Options: &descriptorV1.ServiceOptions{Deprecated: protoV1.Bool(true)},
+ Options: &descriptorV1.ServiceOptions{Deprecated: scalar.Bool(true)},
Methods: []Method{{
Name: "M", // "test.S.M"
InputType: PlaceholderMessage("test.A"),
OutputType: PlaceholderMessage("test.C.A"),
IsStreamingClient: true,
IsStreamingServer: true,
- Options: &descriptorV1.MethodOptions{Deprecated: protoV1.Bool(true)},
+ Options: &descriptorV1.MethodOptions{Deprecated: scalar.Bool(true)},
}},
}},
}
@@ -249,147 +250,147 @@
}
f2 := &descriptorV1.FileDescriptorProto{
- Syntax: protoV1.String("proto2"),
- Name: protoV1.String("path/to/file.proto"),
- Package: protoV1.String("test"),
- Options: &descriptorV1.FileOptions{Deprecated: protoV1.Bool(true)},
+ Syntax: scalar.String("proto2"),
+ Name: scalar.String("path/to/file.proto"),
+ Package: scalar.String("test"),
+ Options: &descriptorV1.FileOptions{Deprecated: scalar.Bool(true)},
MessageType: []*descriptorV1.DescriptorProto{{
- Name: protoV1.String("A"),
+ Name: scalar.String("A"),
Options: &descriptorV1.MessageOptions{
- MapEntry: protoV1.Bool(true),
- Deprecated: protoV1.Bool(true),
+ MapEntry: scalar.Bool(true),
+ Deprecated: scalar.Bool(true),
},
Field: []*descriptorV1.FieldDescriptorProto{{
- Name: protoV1.String("key"),
- Number: protoV1.Int32(1),
- Options: &descriptorV1.FieldOptions{Deprecated: protoV1.Bool(true)},
+ Name: scalar.String("key"),
+ Number: scalar.Int32(1),
+ Options: &descriptorV1.FieldOptions{Deprecated: scalar.Bool(true)},
Label: descriptorV1.FieldDescriptorProto_Label(pref.Optional).Enum(),
Type: descriptorV1.FieldDescriptorProto_Type(pref.StringKind).Enum(),
}, {
- Name: protoV1.String("value"),
- Number: protoV1.Int32(2),
+ Name: scalar.String("value"),
+ Number: scalar.Int32(2),
Label: descriptorV1.FieldDescriptorProto_Label(pref.Optional).Enum(),
Type: descriptorV1.FieldDescriptorProto_Type(pref.MessageKind).Enum(),
- TypeName: protoV1.String(".test.B"),
+ TypeName: scalar.String(".test.B"),
}},
}, {
- Name: protoV1.String("B"),
+ Name: scalar.String("B"),
Field: []*descriptorV1.FieldDescriptorProto{{
- Name: protoV1.String("field_one"),
- Number: protoV1.Int32(1),
+ Name: scalar.String("field_one"),
+ Number: scalar.Int32(1),
Label: descriptorV1.FieldDescriptorProto_Label(pref.Optional).Enum(),
Type: descriptorV1.FieldDescriptorProto_Type(pref.StringKind).Enum(),
- DefaultValue: protoV1.String("hello, \"world!\"\n"),
- OneofIndex: protoV1.Int32(0),
+ DefaultValue: scalar.String("hello, \"world!\"\n"),
+ OneofIndex: scalar.Int32(0),
}, {
- Name: protoV1.String("field_two"),
- JsonName: protoV1.String("Field2"),
- Number: protoV1.Int32(2),
+ Name: scalar.String("field_two"),
+ JsonName: scalar.String("Field2"),
+ Number: scalar.Int32(2),
Label: descriptorV1.FieldDescriptorProto_Label(pref.Optional).Enum(),
Type: descriptorV1.FieldDescriptorProto_Type(pref.EnumKind).Enum(),
- DefaultValue: protoV1.String("BAR"),
- TypeName: protoV1.String(".test.E1"),
- OneofIndex: protoV1.Int32(1),
+ DefaultValue: scalar.String("BAR"),
+ TypeName: scalar.String(".test.E1"),
+ OneofIndex: scalar.Int32(1),
}, {
- Name: protoV1.String("field_three"),
- Number: protoV1.Int32(3),
+ Name: scalar.String("field_three"),
+ Number: scalar.Int32(3),
Label: descriptorV1.FieldDescriptorProto_Label(pref.Optional).Enum(),
Type: descriptorV1.FieldDescriptorProto_Type(pref.MessageKind).Enum(),
- TypeName: protoV1.String(".test.C"),
- OneofIndex: protoV1.Int32(1),
+ TypeName: scalar.String(".test.C"),
+ OneofIndex: scalar.Int32(1),
}, {
- Name: protoV1.String("field_four"),
- JsonName: protoV1.String("Field4"),
- Number: protoV1.Int32(4),
+ Name: scalar.String("field_four"),
+ JsonName: scalar.String("Field4"),
+ Number: scalar.Int32(4),
Label: descriptorV1.FieldDescriptorProto_Label(pref.Repeated).Enum(),
Type: descriptorV1.FieldDescriptorProto_Type(pref.MessageKind).Enum(),
- TypeName: protoV1.String(".test.A"),
+ TypeName: scalar.String(".test.A"),
}, {
- Name: protoV1.String("field_five"),
- Number: protoV1.Int32(5),
+ Name: scalar.String("field_five"),
+ Number: scalar.Int32(5),
Label: descriptorV1.FieldDescriptorProto_Label(pref.Repeated).Enum(),
Type: descriptorV1.FieldDescriptorProto_Type(pref.Int32Kind).Enum(),
- Options: &descriptorV1.FieldOptions{Packed: protoV1.Bool(true)},
+ Options: &descriptorV1.FieldOptions{Packed: scalar.Bool(true)},
}, {
- Name: protoV1.String("field_six"),
- Number: protoV1.Int32(6),
+ Name: scalar.String("field_six"),
+ Number: scalar.Int32(6),
Label: descriptorV1.FieldDescriptorProto_Label(pref.Required).Enum(),
Type: descriptorV1.FieldDescriptorProto_Type(pref.BytesKind).Enum(),
}},
OneofDecl: []*descriptorV1.OneofDescriptorProto{
{
- Name: protoV1.String("O1"),
+ Name: scalar.String("O1"),
Options: &descriptorV1.OneofOptions{
UninterpretedOption: []*descriptorV1.UninterpretedOption{
{StringValue: []byte("option")},
},
},
},
- {Name: protoV1.String("O2")},
+ {Name: scalar.String("O2")},
},
ExtensionRange: []*descriptorV1.DescriptorProto_ExtensionRange{
- {Start: protoV1.Int32(1000), End: protoV1.Int32(2000)},
- {Start: protoV1.Int32(3000), End: protoV1.Int32(3001)},
+ {Start: scalar.Int32(1000), End: scalar.Int32(2000)},
+ {Start: scalar.Int32(3000), End: scalar.Int32(3001)},
},
}, {
- Name: protoV1.String("C"),
+ Name: scalar.String("C"),
NestedType: []*descriptorV1.DescriptorProto{{
- Name: protoV1.String("A"),
+ Name: scalar.String("A"),
Field: []*descriptorV1.FieldDescriptorProto{{
- Name: protoV1.String("F"),
- Number: protoV1.Int32(1),
+ Name: scalar.String("F"),
+ Number: scalar.Int32(1),
Label: descriptorV1.FieldDescriptorProto_Label(pref.Required).Enum(),
Type: descriptorV1.FieldDescriptorProto_Type(pref.BytesKind).Enum(),
- DefaultValue: protoV1.String(`dead\276\357`),
+ DefaultValue: scalar.String(`dead\276\357`),
}},
}},
EnumType: []*descriptorV1.EnumDescriptorProto{{
- Name: protoV1.String("E1"),
+ Name: scalar.String("E1"),
Value: []*descriptorV1.EnumValueDescriptorProto{
- {Name: protoV1.String("FOO"), Number: protoV1.Int32(0)},
- {Name: protoV1.String("BAR"), Number: protoV1.Int32(1)},
+ {Name: scalar.String("FOO"), Number: scalar.Int32(0)},
+ {Name: scalar.String("BAR"), Number: scalar.Int32(1)},
},
}},
Extension: []*descriptorV1.FieldDescriptorProto{{
- Name: protoV1.String("X"),
- Number: protoV1.Int32(1000),
+ Name: scalar.String("X"),
+ Number: scalar.Int32(1000),
Label: descriptorV1.FieldDescriptorProto_Label(pref.Repeated).Enum(),
Type: descriptorV1.FieldDescriptorProto_Type(pref.MessageKind).Enum(),
- TypeName: protoV1.String(".test.C"),
- Extendee: protoV1.String(".test.B"),
+ TypeName: scalar.String(".test.C"),
+ Extendee: scalar.String(".test.B"),
}},
}},
EnumType: []*descriptorV1.EnumDescriptorProto{{
- Name: protoV1.String("E1"),
- Options: &descriptorV1.EnumOptions{Deprecated: protoV1.Bool(true)},
+ Name: scalar.String("E1"),
+ Options: &descriptorV1.EnumOptions{Deprecated: scalar.Bool(true)},
Value: []*descriptorV1.EnumValueDescriptorProto{
{
- Name: protoV1.String("FOO"),
- Number: protoV1.Int32(0),
- Options: &descriptorV1.EnumValueOptions{Deprecated: protoV1.Bool(true)},
+ Name: scalar.String("FOO"),
+ Number: scalar.Int32(0),
+ Options: &descriptorV1.EnumValueOptions{Deprecated: scalar.Bool(true)},
},
- {Name: protoV1.String("BAR"), Number: protoV1.Int32(1)},
+ {Name: scalar.String("BAR"), Number: scalar.Int32(1)},
},
}},
Extension: []*descriptorV1.FieldDescriptorProto{{
- Name: protoV1.String("X"),
- Number: protoV1.Int32(1000),
+ Name: scalar.String("X"),
+ Number: scalar.Int32(1000),
Label: descriptorV1.FieldDescriptorProto_Label(pref.Repeated).Enum(),
Type: descriptorV1.FieldDescriptorProto_Type(pref.MessageKind).Enum(),
- Options: &descriptorV1.FieldOptions{Packed: protoV1.Bool(true)},
- TypeName: protoV1.String(".test.C"),
- Extendee: protoV1.String(".test.B"),
+ Options: &descriptorV1.FieldOptions{Packed: scalar.Bool(true)},
+ TypeName: scalar.String(".test.C"),
+ Extendee: scalar.String(".test.B"),
}},
Service: []*descriptorV1.ServiceDescriptorProto{{
- Name: protoV1.String("S"),
- Options: &descriptorV1.ServiceOptions{Deprecated: protoV1.Bool(true)},
+ Name: scalar.String("S"),
+ Options: &descriptorV1.ServiceOptions{Deprecated: scalar.Bool(true)},
Method: []*descriptorV1.MethodDescriptorProto{{
- Name: protoV1.String("M"),
- InputType: protoV1.String(".test.A"),
- OutputType: protoV1.String(".test.C.A"),
- ClientStreaming: protoV1.Bool(true),
- ServerStreaming: protoV1.Bool(true),
- Options: &descriptorV1.MethodOptions{Deprecated: protoV1.Bool(true)},
+ Name: scalar.String("M"),
+ InputType: scalar.String(".test.A"),
+ OutputType: scalar.String(".test.C.A"),
+ ClientStreaming: scalar.Bool(true),
+ ServerStreaming: scalar.Bool(true),
+ Options: &descriptorV1.MethodOptions{Deprecated: scalar.Bool(true)},
}},
}},
}
@@ -430,7 +431,7 @@
"Path": "path/to/file.proto",
"Package": pref.FullName("test"),
"IsPlaceholder": false,
- "Options": &descriptorV1.FileOptions{Deprecated: protoV1.Bool(true)},
+ "Options": &descriptorV1.FileOptions{Deprecated: scalar.Bool(true)},
"Messages": M{
"Len": 3,
"Get:0": M{
@@ -442,8 +443,8 @@
"IsPlaceholder": false,
"IsMapEntry": true,
"Options": &descriptorV1.MessageOptions{
- MapEntry: protoV1.Bool(true),
- Deprecated: protoV1.Bool(true),
+ MapEntry: scalar.Bool(true),
+ Deprecated: scalar.Bool(true),
},
"Fields": M{
"Len": 2,
@@ -455,7 +456,7 @@
"Number": pref.FieldNumber(1),
"Cardinality": pref.Optional,
"Kind": pref.StringKind,
- "Options": &descriptorV1.FieldOptions{Deprecated: protoV1.Bool(true)},
+ "Options": &descriptorV1.FieldOptions{Deprecated: scalar.Bool(true)},
"JSONName": "key",
"IsPacked": false,
"IsMap": false,
@@ -603,13 +604,13 @@
"Len": 1,
"Get:0": M{
"Name": pref.Name("E1"),
- "Options": &descriptorV1.EnumOptions{Deprecated: protoV1.Bool(true)},
+ "Options": &descriptorV1.EnumOptions{Deprecated: scalar.Bool(true)},
"Values": M{
"Len": 2,
"ByName:Foo": nil,
"ByName:FOO": M{
"FullName": pref.FullName("test.FOO"),
- "Options": &descriptorV1.EnumValueOptions{Deprecated: protoV1.Bool(true)},
+ "Options": &descriptorV1.EnumValueOptions{Deprecated: scalar.Bool(true)},
},
"ByNumber:2": nil,
"ByNumber:1": M{"FullName": pref.FullName("test.BAR")},
@@ -626,7 +627,7 @@
"IsPacked": true,
"MessageType": M{"FullName": pref.FullName("test.C"), "IsPlaceholder": false},
"ExtendedType": M{"FullName": pref.FullName("test.B"), "IsPlaceholder": false},
- "Options": &descriptorV1.FieldOptions{Packed: protoV1.Bool(true)},
+ "Options": &descriptorV1.FieldOptions{Packed: scalar.Bool(true)},
},
},
"Services": M{
@@ -636,7 +637,7 @@
"Parent": M{"FullName": pref.FullName("test")},
"Name": pref.Name("S"),
"FullName": pref.FullName("test.S"),
- "Options": &descriptorV1.ServiceOptions{Deprecated: protoV1.Bool(true)},
+ "Options": &descriptorV1.ServiceOptions{Deprecated: scalar.Bool(true)},
"Methods": M{
"Len": 1,
"Get:0": M{
@@ -647,7 +648,7 @@
"OutputType": M{"FullName": pref.FullName("test.C.A"), "IsPlaceholder": false},
"IsStreamingClient": true,
"IsStreamingServer": true,
- "Options": &descriptorV1.MethodOptions{Deprecated: protoV1.Bool(true)},
+ "Options": &descriptorV1.MethodOptions{Deprecated: scalar.Bool(true)},
},
},
},