aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Shiraishi <zchee.io@gmail.com>2022-05-24 05:12:23 +0900
committerDamien Neil <dneil@google.com>2022-05-24 20:05:50 +0000
commit784c4825545540dc41a1dc85715d3251903bc8ce (patch)
tree7061cc5551de60bd247796faa34b36437940ea85
parente62d8edb7570c986a51e541c161a0c93bbaf9253 (diff)
downloadgolang-protobuf-784c4825545540dc41a1dc85715d3251903bc8ce.tar.gz
all: remove shorthand import aliases
Change-Id: I62ec79419354a2c65ac69e4bcc1cc864a6a40a1a Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/407934 Reviewed-by: Lasse Folger <lassefolger@google.com> Reviewed-by: Damien Neil <dneil@google.com>
-rw-r--r--encoding/bench_test.go58
-rw-r--r--encoding/protojson/decode.go174
-rw-r--r--encoding/protojson/decode_test.go4
-rw-r--r--encoding/protojson/encode_test.go4
-rw-r--r--encoding/protojson/well_known_types.go76
-rw-r--r--encoding/prototext/decode.go116
-rw-r--r--encoding/prototext/decode_test.go4
-rw-r--r--encoding/prototext/encode_test.go4
-rw-r--r--encoding/prototext/other_test.go6
-rw-r--r--internal/benchmarks/bench_test.go8
-rw-r--r--internal/cmd/pbdump/pbdump_test.go24
-rw-r--r--internal/descfmt/stringer.go66
-rw-r--r--internal/encoding/defval/default.go78
-rw-r--r--internal/encoding/defval/default_test.go34
-rw-r--r--internal/encoding/messageset/messageset.go6
-rw-r--r--internal/encoding/tag/tag.go96
-rw-r--r--internal/encoding/tag/tag_test.go18
-rw-r--r--internal/filedesc/desc.go380
-rw-r--r--internal/filedesc/desc_init.go36
-rw-r--r--internal/filedesc/desc_lazy.go80
-rw-r--r--internal/filedesc/desc_test.go204
-rw-r--r--internal/filedesc/placeholder.go136
-rw-r--r--internal/filetype/build.go84
-rw-r--r--internal/impl/api_export.go42
-rw-r--r--internal/impl/checkinit.go12
-rw-r--r--internal/impl/codec_extension.go36
-rw-r--r--internal/impl/codec_field.go90
-rw-r--r--internal/impl/codec_map.go20
-rw-r--r--internal/impl/codec_message.go30
-rw-r--r--internal/impl/codec_tables.go290
-rw-r--r--internal/impl/convert.go228
-rw-r--r--internal/impl/convert_list.go42
-rw-r--r--internal/impl/convert_map.go32
-rw-r--r--internal/impl/enum.go10
-rw-r--r--internal/impl/enum_test.go4
-rw-r--r--internal/impl/extension.go26
-rw-r--r--internal/impl/extension_test.go4
-rw-r--r--internal/impl/legacy_export.go14
-rw-r--r--internal/impl/legacy_extension.go100
-rw-r--r--internal/impl/legacy_file_test.go40
-rw-r--r--internal/impl/legacy_test.go52
-rw-r--r--internal/impl/merge.go32
-rw-r--r--internal/impl/message_reflect.go64
-rw-r--r--internal/impl/message_reflect_field.go118
-rw-r--r--internal/impl/message_reflect_test.go186
-rw-r--r--internal/impl/validate.go50
-rw-r--r--internal/impl/weak.go16
-rw-r--r--internal/order/order.go16
-rw-r--r--internal/order/range.go18
-rw-r--r--internal/protobuild/build.go42
-rw-r--r--internal/strs/strings_unsafe.go6
-rw-r--r--internal/testprotos/irregular/irregular.go46
-rw-r--r--proto/encode_test.go6
-rw-r--r--proto/equal.go46
-rw-r--r--reflect/protoregistry/registry_test.go88
-rw-r--r--testing/prototest/enum.go4
-rw-r--r--types/dynamicpb/dynamic.go320
-rw-r--r--types/dynamicpb/dynamic_test.go18
58 files changed, 1926 insertions, 1918 deletions
diff --git a/encoding/bench_test.go b/encoding/bench_test.go
index ce95512e..4be28e33 100644
--- a/encoding/bench_test.go
+++ b/encoding/bench_test.go
@@ -10,7 +10,7 @@ import (
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/encoding/prototext"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
tpb "google.golang.org/protobuf/internal/testprotos/test"
)
@@ -27,7 +27,7 @@ func makeProto() *tpb.TestAllTypes {
return m
}
-func fillMessage(m pref.Message, level int) {
+func fillMessage(m protoreflect.Message, level int) {
if level > maxRecurseLevel {
return
}
@@ -46,9 +46,9 @@ func fillMessage(m pref.Message, level int) {
}
}
-func setScalarField(m pref.Message, fd pref.FieldDescriptor, level int) {
+func setScalarField(m protoreflect.Message, fd protoreflect.FieldDescriptor, level int) {
switch fd.Kind() {
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
val := m.NewField(fd)
fillMessage(val.Message(), level+1)
m.Set(fd, val)
@@ -57,45 +57,45 @@ func setScalarField(m pref.Message, fd pref.FieldDescriptor, level int) {
}
}
-func scalarField(kind pref.Kind) pref.Value {
+func scalarField(kind protoreflect.Kind) protoreflect.Value {
switch kind {
- case pref.BoolKind:
- return pref.ValueOfBool(true)
+ case protoreflect.BoolKind:
+ return protoreflect.ValueOfBool(true)
- case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
- return pref.ValueOfInt32(1 << 30)
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
+ return protoreflect.ValueOfInt32(1 << 30)
- case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
- return pref.ValueOfInt64(1 << 30)
+ case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
+ return protoreflect.ValueOfInt64(1 << 30)
- case pref.Uint32Kind, pref.Fixed32Kind:
- return pref.ValueOfUint32(1 << 30)
+ case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
+ return protoreflect.ValueOfUint32(1 << 30)
- case pref.Uint64Kind, pref.Fixed64Kind:
- return pref.ValueOfUint64(1 << 30)
+ case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
+ return protoreflect.ValueOfUint64(1 << 30)
- case pref.FloatKind:
- return pref.ValueOfFloat32(3.14159265)
+ case protoreflect.FloatKind:
+ return protoreflect.ValueOfFloat32(3.14159265)
- case pref.DoubleKind:
- return pref.ValueOfFloat64(3.14159265)
+ case protoreflect.DoubleKind:
+ return protoreflect.ValueOfFloat64(3.14159265)
- case pref.BytesKind:
- return pref.ValueOfBytes([]byte("hello world"))
+ case protoreflect.BytesKind:
+ return protoreflect.ValueOfBytes([]byte("hello world"))
- case pref.StringKind:
- return pref.ValueOfString("hello world")
+ case protoreflect.StringKind:
+ return protoreflect.ValueOfString("hello world")
- case pref.EnumKind:
- return pref.ValueOfEnum(42)
+ case protoreflect.EnumKind:
+ return protoreflect.ValueOfEnum(42)
}
panic(fmt.Sprintf("FieldDescriptor.Kind %v is not valid", kind))
}
-func setList(list pref.List, fd pref.FieldDescriptor, level int) {
+func setList(list protoreflect.List, fd protoreflect.FieldDescriptor, level int) {
switch fd.Kind() {
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
for i := 0; i < 10; i++ {
val := list.NewElement()
fillMessage(val.Message(), level+1)
@@ -108,14 +108,14 @@ func setList(list pref.List, fd pref.FieldDescriptor, level int) {
}
}
-func setMap(mmap pref.Map, fd pref.FieldDescriptor, level int) {
+func setMap(mmap protoreflect.Map, fd protoreflect.FieldDescriptor, level int) {
fields := fd.Message().Fields()
keyDesc := fields.ByNumber(1)
valDesc := fields.ByNumber(2)
pkey := scalarField(keyDesc.Kind())
switch kind := valDesc.Kind(); kind {
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
val := mmap.NewValue()
fillMessage(val.Message(), level+1)
mmap.Set(pkey.MapKey(), val)
diff --git a/encoding/protojson/decode.go b/encoding/protojson/decode.go
index 07da5db3..5f28148d 100644
--- a/encoding/protojson/decode.go
+++ b/encoding/protojson/decode.go
@@ -19,7 +19,7 @@ import (
"google.golang.org/protobuf/internal/pragma"
"google.golang.org/protobuf/internal/set"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
)
@@ -113,7 +113,7 @@ func (d decoder) syntaxError(pos int, f string, x ...interface{}) error {
}
// unmarshalMessage unmarshals a message into the given protoreflect.Message.
-func (d decoder) unmarshalMessage(m pref.Message, skipTypeURL bool) error {
+func (d decoder) unmarshalMessage(m protoreflect.Message, skipTypeURL bool) error {
if unmarshal := wellKnownTypeUnmarshaler(m.Descriptor().FullName()); unmarshal != nil {
return unmarshal(d, m)
}
@@ -159,10 +159,10 @@ func (d decoder) unmarshalMessage(m pref.Message, skipTypeURL bool) error {
}
// Get the FieldDescriptor.
- var fd pref.FieldDescriptor
+ var fd protoreflect.FieldDescriptor
if strings.HasPrefix(name, "[") && strings.HasSuffix(name, "]") {
// Only extension names are in [name] format.
- extName := pref.FullName(name[1 : len(name)-1])
+ extName := protoreflect.FullName(name[1 : len(name)-1])
extType, err := d.opts.Resolver.FindExtensionByName(extName)
if err != nil && err != protoregistry.NotFound {
return d.newError(tok.Pos(), "unable to resolve %s: %v", tok.RawString(), err)
@@ -240,23 +240,23 @@ func (d decoder) unmarshalMessage(m pref.Message, skipTypeURL bool) error {
}
}
-func isKnownValue(fd pref.FieldDescriptor) bool {
+func isKnownValue(fd protoreflect.FieldDescriptor) bool {
md := fd.Message()
return md != nil && md.FullName() == genid.Value_message_fullname
}
-func isNullValue(fd pref.FieldDescriptor) bool {
+func isNullValue(fd protoreflect.FieldDescriptor) bool {
ed := fd.Enum()
return ed != nil && ed.FullName() == genid.NullValue_enum_fullname
}
// unmarshalSingular unmarshals to the non-repeated field specified
// by the given FieldDescriptor.
-func (d decoder) unmarshalSingular(m pref.Message, fd pref.FieldDescriptor) error {
- var val pref.Value
+func (d decoder) unmarshalSingular(m protoreflect.Message, fd protoreflect.FieldDescriptor) error {
+ var val protoreflect.Value
var err error
switch fd.Kind() {
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
val = m.NewField(fd)
err = d.unmarshalMessage(val.Message(), false)
default:
@@ -272,63 +272,63 @@ func (d decoder) unmarshalSingular(m pref.Message, fd pref.FieldDescriptor) erro
// unmarshalScalar unmarshals to a scalar/enum protoreflect.Value specified by
// the given FieldDescriptor.
-func (d decoder) unmarshalScalar(fd pref.FieldDescriptor) (pref.Value, error) {
+func (d decoder) unmarshalScalar(fd protoreflect.FieldDescriptor) (protoreflect.Value, error) {
const b32 int = 32
const b64 int = 64
tok, err := d.Read()
if err != nil {
- return pref.Value{}, err
+ return protoreflect.Value{}, err
}
kind := fd.Kind()
switch kind {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
if tok.Kind() == json.Bool {
- return pref.ValueOfBool(tok.Bool()), nil
+ return protoreflect.ValueOfBool(tok.Bool()), nil
}
- case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
if v, ok := unmarshalInt(tok, b32); ok {
return v, nil
}
- case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
+ case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
if v, ok := unmarshalInt(tok, b64); ok {
return v, nil
}
- case pref.Uint32Kind, pref.Fixed32Kind:
+ case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
if v, ok := unmarshalUint(tok, b32); ok {
return v, nil
}
- case pref.Uint64Kind, pref.Fixed64Kind:
+ case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
if v, ok := unmarshalUint(tok, b64); ok {
return v, nil
}
- case pref.FloatKind:
+ case protoreflect.FloatKind:
if v, ok := unmarshalFloat(tok, b32); ok {
return v, nil
}
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
if v, ok := unmarshalFloat(tok, b64); ok {
return v, nil
}
- case pref.StringKind:
+ case protoreflect.StringKind:
if tok.Kind() == json.String {
- return pref.ValueOfString(tok.ParsedString()), nil
+ return protoreflect.ValueOfString(tok.ParsedString()), nil
}
- case pref.BytesKind:
+ case protoreflect.BytesKind:
if v, ok := unmarshalBytes(tok); ok {
return v, nil
}
- case pref.EnumKind:
+ case protoreflect.EnumKind:
if v, ok := unmarshalEnum(tok, fd); ok {
return v, nil
}
@@ -337,10 +337,10 @@ func (d decoder) unmarshalScalar(fd pref.FieldDescriptor) (pref.Value, error) {
panic(fmt.Sprintf("unmarshalScalar: invalid scalar kind %v", kind))
}
- return pref.Value{}, d.newError(tok.Pos(), "invalid value for %v type: %v", kind, tok.RawString())
+ return protoreflect.Value{}, d.newError(tok.Pos(), "invalid value for %v type: %v", kind, tok.RawString())
}
-func unmarshalInt(tok json.Token, bitSize int) (pref.Value, bool) {
+func unmarshalInt(tok json.Token, bitSize int) (protoreflect.Value, bool) {
switch tok.Kind() {
case json.Number:
return getInt(tok, bitSize)
@@ -349,30 +349,30 @@ func unmarshalInt(tok json.Token, bitSize int) (pref.Value, bool) {
// Decode number from string.
s := strings.TrimSpace(tok.ParsedString())
if len(s) != len(tok.ParsedString()) {
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
dec := json.NewDecoder([]byte(s))
tok, err := dec.Read()
if err != nil {
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
return getInt(tok, bitSize)
}
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
-func getInt(tok json.Token, bitSize int) (pref.Value, bool) {
+func getInt(tok json.Token, bitSize int) (protoreflect.Value, bool) {
n, ok := tok.Int(bitSize)
if !ok {
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
if bitSize == 32 {
- return pref.ValueOfInt32(int32(n)), true
+ return protoreflect.ValueOfInt32(int32(n)), true
}
- return pref.ValueOfInt64(n), true
+ return protoreflect.ValueOfInt64(n), true
}
-func unmarshalUint(tok json.Token, bitSize int) (pref.Value, bool) {
+func unmarshalUint(tok json.Token, bitSize int) (protoreflect.Value, bool) {
switch tok.Kind() {
case json.Number:
return getUint(tok, bitSize)
@@ -381,30 +381,30 @@ func unmarshalUint(tok json.Token, bitSize int) (pref.Value, bool) {
// Decode number from string.
s := strings.TrimSpace(tok.ParsedString())
if len(s) != len(tok.ParsedString()) {
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
dec := json.NewDecoder([]byte(s))
tok, err := dec.Read()
if err != nil {
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
return getUint(tok, bitSize)
}
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
-func getUint(tok json.Token, bitSize int) (pref.Value, bool) {
+func getUint(tok json.Token, bitSize int) (protoreflect.Value, bool) {
n, ok := tok.Uint(bitSize)
if !ok {
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
if bitSize == 32 {
- return pref.ValueOfUint32(uint32(n)), true
+ return protoreflect.ValueOfUint32(uint32(n)), true
}
- return pref.ValueOfUint64(n), true
+ return protoreflect.ValueOfUint64(n), true
}
-func unmarshalFloat(tok json.Token, bitSize int) (pref.Value, bool) {
+func unmarshalFloat(tok json.Token, bitSize int) (protoreflect.Value, bool) {
switch tok.Kind() {
case json.Number:
return getFloat(tok, bitSize)
@@ -414,49 +414,49 @@ func unmarshalFloat(tok json.Token, bitSize int) (pref.Value, bool) {
switch s {
case "NaN":
if bitSize == 32 {
- return pref.ValueOfFloat32(float32(math.NaN())), true
+ return protoreflect.ValueOfFloat32(float32(math.NaN())), true
}
- return pref.ValueOfFloat64(math.NaN()), true
+ return protoreflect.ValueOfFloat64(math.NaN()), true
case "Infinity":
if bitSize == 32 {
- return pref.ValueOfFloat32(float32(math.Inf(+1))), true
+ return protoreflect.ValueOfFloat32(float32(math.Inf(+1))), true
}
- return pref.ValueOfFloat64(math.Inf(+1)), true
+ return protoreflect.ValueOfFloat64(math.Inf(+1)), true
case "-Infinity":
if bitSize == 32 {
- return pref.ValueOfFloat32(float32(math.Inf(-1))), true
+ return protoreflect.ValueOfFloat32(float32(math.Inf(-1))), true
}
- return pref.ValueOfFloat64(math.Inf(-1)), true
+ return protoreflect.ValueOfFloat64(math.Inf(-1)), true
}
// Decode number from string.
if len(s) != len(strings.TrimSpace(s)) {
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
dec := json.NewDecoder([]byte(s))
tok, err := dec.Read()
if err != nil {
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
return getFloat(tok, bitSize)
}
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
-func getFloat(tok json.Token, bitSize int) (pref.Value, bool) {
+func getFloat(tok json.Token, bitSize int) (protoreflect.Value, bool) {
n, ok := tok.Float(bitSize)
if !ok {
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
if bitSize == 32 {
- return pref.ValueOfFloat32(float32(n)), true
+ return protoreflect.ValueOfFloat32(float32(n)), true
}
- return pref.ValueOfFloat64(n), true
+ return protoreflect.ValueOfFloat64(n), true
}
-func unmarshalBytes(tok json.Token) (pref.Value, bool) {
+func unmarshalBytes(tok json.Token) (protoreflect.Value, bool) {
if tok.Kind() != json.String {
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
s := tok.ParsedString()
@@ -469,36 +469,36 @@ func unmarshalBytes(tok json.Token) (pref.Value, bool) {
}
b, err := enc.DecodeString(s)
if err != nil {
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
- return pref.ValueOfBytes(b), true
+ return protoreflect.ValueOfBytes(b), true
}
-func unmarshalEnum(tok json.Token, fd pref.FieldDescriptor) (pref.Value, bool) {
+func unmarshalEnum(tok json.Token, fd protoreflect.FieldDescriptor) (protoreflect.Value, bool) {
switch tok.Kind() {
case json.String:
// Lookup EnumNumber based on name.
s := tok.ParsedString()
- if enumVal := fd.Enum().Values().ByName(pref.Name(s)); enumVal != nil {
- return pref.ValueOfEnum(enumVal.Number()), true
+ if enumVal := fd.Enum().Values().ByName(protoreflect.Name(s)); enumVal != nil {
+ return protoreflect.ValueOfEnum(enumVal.Number()), true
}
case json.Number:
if n, ok := tok.Int(32); ok {
- return pref.ValueOfEnum(pref.EnumNumber(n)), true
+ return protoreflect.ValueOfEnum(protoreflect.EnumNumber(n)), true
}
case json.Null:
// This is only valid for google.protobuf.NullValue.
if isNullValue(fd) {
- return pref.ValueOfEnum(0), true
+ return protoreflect.ValueOfEnum(0), true
}
}
- return pref.Value{}, false
+ return protoreflect.Value{}, false
}
-func (d decoder) unmarshalList(list pref.List, fd pref.FieldDescriptor) error {
+func (d decoder) unmarshalList(list protoreflect.List, fd protoreflect.FieldDescriptor) error {
tok, err := d.Read()
if err != nil {
return err
@@ -508,7 +508,7 @@ func (d decoder) unmarshalList(list pref.List, fd pref.FieldDescriptor) error {
}
switch fd.Kind() {
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
for {
tok, err := d.Peek()
if err != nil {
@@ -549,7 +549,7 @@ func (d decoder) unmarshalList(list pref.List, fd pref.FieldDescriptor) error {
return nil
}
-func (d decoder) unmarshalMap(mmap pref.Map, fd pref.FieldDescriptor) error {
+func (d decoder) unmarshalMap(mmap protoreflect.Map, fd protoreflect.FieldDescriptor) error {
tok, err := d.Read()
if err != nil {
return err
@@ -561,18 +561,18 @@ func (d decoder) unmarshalMap(mmap pref.Map, fd pref.FieldDescriptor) error {
// Determine ahead whether map entry is a scalar type or a message type in
// order to call the appropriate unmarshalMapValue func inside the for loop
// below.
- var unmarshalMapValue func() (pref.Value, error)
+ var unmarshalMapValue func() (protoreflect.Value, error)
switch fd.MapValue().Kind() {
- case pref.MessageKind, pref.GroupKind:
- unmarshalMapValue = func() (pref.Value, error) {
+ case protoreflect.MessageKind, protoreflect.GroupKind:
+ unmarshalMapValue = func() (protoreflect.Value, error) {
val := mmap.NewValue()
if err := d.unmarshalMessage(val.Message(), false); err != nil {
- return pref.Value{}, err
+ return protoreflect.Value{}, err
}
return val, nil
}
default:
- unmarshalMapValue = func() (pref.Value, error) {
+ unmarshalMapValue = func() (protoreflect.Value, error) {
return d.unmarshalScalar(fd.MapValue())
}
}
@@ -618,7 +618,7 @@ Loop:
// unmarshalMapKey converts given token of Name kind into a protoreflect.MapKey.
// A map key type is any integral or string type.
-func (d decoder) unmarshalMapKey(tok json.Token, fd pref.FieldDescriptor) (pref.MapKey, error) {
+func (d decoder) unmarshalMapKey(tok json.Token, fd protoreflect.FieldDescriptor) (protoreflect.MapKey, error) {
const b32 = 32
const b64 = 64
const base10 = 10
@@ -626,40 +626,40 @@ func (d decoder) unmarshalMapKey(tok json.Token, fd pref.FieldDescriptor) (pref.
name := tok.Name()
kind := fd.Kind()
switch kind {
- case pref.StringKind:
- return pref.ValueOfString(name).MapKey(), nil
+ case protoreflect.StringKind:
+ return protoreflect.ValueOfString(name).MapKey(), nil
- case pref.BoolKind:
+ case protoreflect.BoolKind:
switch name {
case "true":
- return pref.ValueOfBool(true).MapKey(), nil
+ return protoreflect.ValueOfBool(true).MapKey(), nil
case "false":
- return pref.ValueOfBool(false).MapKey(), nil
+ return protoreflect.ValueOfBool(false).MapKey(), nil
}
- case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
if n, err := strconv.ParseInt(name, base10, b32); err == nil {
- return pref.ValueOfInt32(int32(n)).MapKey(), nil
+ return protoreflect.ValueOfInt32(int32(n)).MapKey(), nil
}
- case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
+ case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
if n, err := strconv.ParseInt(name, base10, b64); err == nil {
- return pref.ValueOfInt64(int64(n)).MapKey(), nil
+ return protoreflect.ValueOfInt64(int64(n)).MapKey(), nil
}
- case pref.Uint32Kind, pref.Fixed32Kind:
+ case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
if n, err := strconv.ParseUint(name, base10, b32); err == nil {
- return pref.ValueOfUint32(uint32(n)).MapKey(), nil
+ return protoreflect.ValueOfUint32(uint32(n)).MapKey(), nil
}
- case pref.Uint64Kind, pref.Fixed64Kind:
+ case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
if n, err := strconv.ParseUint(name, base10, b64); err == nil {
- return pref.ValueOfUint64(uint64(n)).MapKey(), nil
+ return protoreflect.ValueOfUint64(uint64(n)).MapKey(), nil
}
default:
panic(fmt.Sprintf("invalid kind for map key: %v", kind))
}
- return pref.MapKey{}, d.newError(tok.Pos(), "invalid value for %v key: %s", kind, tok.RawString())
+ return protoreflect.MapKey{}, d.newError(tok.Pos(), "invalid value for %v key: %s", kind, tok.RawString())
}
diff --git a/encoding/protojson/decode_test.go b/encoding/protojson/decode_test.go
index 4791f650..3653ccbc 100644
--- a/encoding/protojson/decode_test.go
+++ b/encoding/protojson/decode_test.go
@@ -13,7 +13,7 @@ import (
"google.golang.org/protobuf/internal/errors"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/proto"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protoregistry"
testpb "google.golang.org/protobuf/internal/testprotos/test"
weakpb "google.golang.org/protobuf/internal/testprotos/test/weak1"
@@ -1984,7 +1984,7 @@ func TestUnmarshal(t *testing.T) {
wantMessage: &anypb.Any{TypeUrl: "foo/pb2.Nested"},
}, {
desc: "Any without registered type",
- umo: protojson.UnmarshalOptions{Resolver: new(preg.Types)},
+ umo: protojson.UnmarshalOptions{Resolver: new(protoregistry.Types)},
inputMessage: &anypb.Any{},
inputText: `{"@type": "foo/pb2.Nested"}`,
wantErr: `(line 1:11): unable to resolve "foo/pb2.Nested":`,
diff --git a/encoding/protojson/encode_test.go b/encoding/protojson/encode_test.go
index f1a05fe1..e8db20b0 100644
--- a/encoding/protojson/encode_test.go
+++ b/encoding/protojson/encode_test.go
@@ -15,7 +15,7 @@ import (
"google.golang.org/protobuf/internal/detrand"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/proto"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/testing/protopack"
pb2 "google.golang.org/protobuf/internal/testprotos/textpb2"
@@ -1585,7 +1585,7 @@ func TestMarshal(t *testing.T) {
}`,
}, {
desc: "Any without registered type",
- mo: protojson.MarshalOptions{Resolver: new(preg.Types)},
+ mo: protojson.MarshalOptions{Resolver: new(protoregistry.Types)},
input: &anypb.Any{TypeUrl: "foo/pb2.Nested"},
wantErr: true,
}, {
diff --git a/encoding/protojson/well_known_types.go b/encoding/protojson/well_known_types.go
index 72924a90..c85f8469 100644
--- a/encoding/protojson/well_known_types.go
+++ b/encoding/protojson/well_known_types.go
@@ -17,14 +17,14 @@ import (
"google.golang.org/protobuf/internal/genid"
"google.golang.org/protobuf/internal/strs"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
-type marshalFunc func(encoder, pref.Message) error
+type marshalFunc func(encoder, protoreflect.Message) error
// wellKnownTypeMarshaler returns a marshal function if the message type
// has specialized serialization behavior. It returns nil otherwise.
-func wellKnownTypeMarshaler(name pref.FullName) marshalFunc {
+func wellKnownTypeMarshaler(name protoreflect.FullName) marshalFunc {
if name.Parent() == genid.GoogleProtobuf_package {
switch name.Name() {
case genid.Any_message_name:
@@ -58,11 +58,11 @@ func wellKnownTypeMarshaler(name pref.FullName) marshalFunc {
return nil
}
-type unmarshalFunc func(decoder, pref.Message) error
+type unmarshalFunc func(decoder, protoreflect.Message) error
// wellKnownTypeUnmarshaler returns a unmarshal function if the message type
// has specialized serialization behavior. It returns nil otherwise.
-func wellKnownTypeUnmarshaler(name pref.FullName) unmarshalFunc {
+func wellKnownTypeUnmarshaler(name protoreflect.FullName) unmarshalFunc {
if name.Parent() == genid.GoogleProtobuf_package {
switch name.Name() {
case genid.Any_message_name:
@@ -102,7 +102,7 @@ func wellKnownTypeUnmarshaler(name pref.FullName) unmarshalFunc {
// custom JSON representation, that representation will be embedded adding a
// field `value` which holds the custom JSON in addition to the `@type` field.
-func (e encoder) marshalAny(m pref.Message) error {
+func (e encoder) marshalAny(m protoreflect.Message) error {
fds := m.Descriptor().Fields()
fdType := fds.ByNumber(genid.Any_TypeUrl_field_number)
fdValue := fds.ByNumber(genid.Any_Value_field_number)
@@ -163,7 +163,7 @@ func (e encoder) marshalAny(m pref.Message) error {
return nil
}
-func (d decoder) unmarshalAny(m pref.Message) error {
+func (d decoder) unmarshalAny(m protoreflect.Message) error {
// Peek to check for json.ObjectOpen to avoid advancing a read.
start, err := d.Peek()
if err != nil {
@@ -233,8 +233,8 @@ func (d decoder) unmarshalAny(m pref.Message) error {
fdType := fds.ByNumber(genid.Any_TypeUrl_field_number)
fdValue := fds.ByNumber(genid.Any_Value_field_number)
- m.Set(fdType, pref.ValueOfString(typeURL))
- m.Set(fdValue, pref.ValueOfBytes(b))
+ m.Set(fdType, protoreflect.ValueOfString(typeURL))
+ m.Set(fdValue, protoreflect.ValueOfBytes(b))
return nil
}
@@ -354,7 +354,7 @@ func (d decoder) skipJSONValue() error {
// unmarshalAnyValue unmarshals the given custom-type message from the JSON
// object's "value" field.
-func (d decoder) unmarshalAnyValue(unmarshal unmarshalFunc, m pref.Message) error {
+func (d decoder) unmarshalAnyValue(unmarshal unmarshalFunc, m protoreflect.Message) error {
// Skip ObjectOpen, and start reading the fields.
d.Read()
@@ -402,13 +402,13 @@ func (d decoder) unmarshalAnyValue(unmarshal unmarshalFunc, m pref.Message) erro
// Wrapper types are encoded as JSON primitives like string, number or boolean.
-func (e encoder) marshalWrapperType(m pref.Message) error {
+func (e encoder) marshalWrapperType(m protoreflect.Message) error {
fd := m.Descriptor().Fields().ByNumber(genid.WrapperValue_Value_field_number)
val := m.Get(fd)
return e.marshalSingular(val, fd)
}
-func (d decoder) unmarshalWrapperType(m pref.Message) error {
+func (d decoder) unmarshalWrapperType(m protoreflect.Message) error {
fd := m.Descriptor().Fields().ByNumber(genid.WrapperValue_Value_field_number)
val, err := d.unmarshalScalar(fd)
if err != nil {
@@ -420,13 +420,13 @@ func (d decoder) unmarshalWrapperType(m pref.Message) error {
// The JSON representation for Empty is an empty JSON object.
-func (e encoder) marshalEmpty(pref.Message) error {
+func (e encoder) marshalEmpty(protoreflect.Message) error {
e.StartObject()
e.EndObject()
return nil
}
-func (d decoder) unmarshalEmpty(pref.Message) error {
+func (d decoder) unmarshalEmpty(protoreflect.Message) error {
tok, err := d.Read()
if err != nil {
return err
@@ -462,12 +462,12 @@ func (d decoder) unmarshalEmpty(pref.Message) error {
// The JSON representation for Struct is a JSON object that contains the encoded
// Struct.fields map and follows the serialization rules for a map.
-func (e encoder) marshalStruct(m pref.Message) error {
+func (e encoder) marshalStruct(m protoreflect.Message) error {
fd := m.Descriptor().Fields().ByNumber(genid.Struct_Fields_field_number)
return e.marshalMap(m.Get(fd).Map(), fd)
}
-func (d decoder) unmarshalStruct(m pref.Message) error {
+func (d decoder) unmarshalStruct(m protoreflect.Message) error {
fd := m.Descriptor().Fields().ByNumber(genid.Struct_Fields_field_number)
return d.unmarshalMap(m.Mutable(fd).Map(), fd)
}
@@ -476,12 +476,12 @@ func (d decoder) unmarshalStruct(m pref.Message) error {
// ListValue.values repeated field and follows the serialization rules for a
// repeated field.
-func (e encoder) marshalListValue(m pref.Message) error {
+func (e encoder) marshalListValue(m protoreflect.Message) error {
fd := m.Descriptor().Fields().ByNumber(genid.ListValue_Values_field_number)
return e.marshalList(m.Get(fd).List(), fd)
}
-func (d decoder) unmarshalListValue(m pref.Message) error {
+func (d decoder) unmarshalListValue(m protoreflect.Message) error {
fd := m.Descriptor().Fields().ByNumber(genid.ListValue_Values_field_number)
return d.unmarshalList(m.Mutable(fd).List(), fd)
}
@@ -490,7 +490,7 @@ func (d decoder) unmarshalListValue(m pref.Message) error {
// set. Each of the field in the oneof has its own custom serialization rule. A
// Value message needs to be a oneof field set, else it is an error.
-func (e encoder) marshalKnownValue(m pref.Message) error {
+func (e encoder) marshalKnownValue(m protoreflect.Message) error {
od := m.Descriptor().Oneofs().ByName(genid.Value_Kind_oneof_name)
fd := m.WhichOneof(od)
if fd == nil {
@@ -504,19 +504,19 @@ func (e encoder) marshalKnownValue(m pref.Message) error {
return e.marshalSingular(m.Get(fd), fd)
}
-func (d decoder) unmarshalKnownValue(m pref.Message) error {
+func (d decoder) unmarshalKnownValue(m protoreflect.Message) error {
tok, err := d.Peek()
if err != nil {
return err
}
- var fd pref.FieldDescriptor
- var val pref.Value
+ var fd protoreflect.FieldDescriptor
+ var val protoreflect.Value
switch tok.Kind() {
case json.Null:
d.Read()
fd = m.Descriptor().Fields().ByNumber(genid.Value_NullValue_field_number)
- val = pref.ValueOfEnum(0)
+ val = protoreflect.ValueOfEnum(0)
case json.Bool:
tok, err := d.Read()
@@ -524,7 +524,7 @@ func (d decoder) unmarshalKnownValue(m pref.Message) error {
return err
}
fd = m.Descriptor().Fields().ByNumber(genid.Value_BoolValue_field_number)
- val = pref.ValueOfBool(tok.Bool())
+ val = protoreflect.ValueOfBool(tok.Bool())
case json.Number:
tok, err := d.Read()
@@ -550,7 +550,7 @@ func (d decoder) unmarshalKnownValue(m pref.Message) error {
return err
}
fd = m.Descriptor().Fields().ByNumber(genid.Value_StringValue_field_number)
- val = pref.ValueOfString(tok.ParsedString())
+ val = protoreflect.ValueOfString(tok.ParsedString())
case json.ObjectOpen:
fd = m.Descriptor().Fields().ByNumber(genid.Value_StructValue_field_number)
@@ -591,7 +591,7 @@ const (
maxSecondsInDuration = 315576000000
)
-func (e encoder) marshalDuration(m pref.Message) error {
+func (e encoder) marshalDuration(m protoreflect.Message) error {
fds := m.Descriptor().Fields()
fdSeconds := fds.ByNumber(genid.Duration_Seconds_field_number)
fdNanos := fds.ByNumber(genid.Duration_Nanos_field_number)
@@ -623,7 +623,7 @@ func (e encoder) marshalDuration(m pref.Message) error {
return nil
}
-func (d decoder) unmarshalDuration(m pref.Message) error {
+func (d decoder) unmarshalDuration(m protoreflect.Message) error {
tok, err := d.Read()
if err != nil {
return err
@@ -646,8 +646,8 @@ func (d decoder) unmarshalDuration(m pref.Message) error {
fdSeconds := fds.ByNumber(genid.Duration_Seconds_field_number)
fdNanos := fds.ByNumber(genid.Duration_Nanos_field_number)
- m.Set(fdSeconds, pref.ValueOfInt64(secs))
- m.Set(fdNanos, pref.ValueOfInt32(nanos))
+ m.Set(fdSeconds, protoreflect.ValueOfInt64(secs))
+ m.Set(fdNanos, protoreflect.ValueOfInt32(nanos))
return nil
}
@@ -779,7 +779,7 @@ const (
minTimestampSeconds = -62135596800
)
-func (e encoder) marshalTimestamp(m pref.Message) error {
+func (e encoder) marshalTimestamp(m protoreflect.Message) error {
fds := m.Descriptor().Fields()
fdSeconds := fds.ByNumber(genid.Timestamp_Seconds_field_number)
fdNanos := fds.ByNumber(genid.Timestamp_Nanos_field_number)
@@ -805,7 +805,7 @@ func (e encoder) marshalTimestamp(m pref.Message) error {
return nil
}
-func (d decoder) unmarshalTimestamp(m pref.Message) error {
+func (d decoder) unmarshalTimestamp(m protoreflect.Message) error {
tok, err := d.Read()
if err != nil {
return err
@@ -829,8 +829,8 @@ func (d decoder) unmarshalTimestamp(m pref.Message) error {
fdSeconds := fds.ByNumber(genid.Timestamp_Seconds_field_number)
fdNanos := fds.ByNumber(genid.Timestamp_Nanos_field_number)
- m.Set(fdSeconds, pref.ValueOfInt64(secs))
- m.Set(fdNanos, pref.ValueOfInt32(int32(t.Nanosecond())))
+ m.Set(fdSeconds, protoreflect.ValueOfInt64(secs))
+ m.Set(fdNanos, protoreflect.ValueOfInt32(int32(t.Nanosecond())))
return nil
}
@@ -839,14 +839,14 @@ func (d decoder) unmarshalTimestamp(m pref.Message) error {
// lower-camel naming conventions. Encoding should fail if the path name would
// end up differently after a round-trip.
-func (e encoder) marshalFieldMask(m pref.Message) error {
+func (e encoder) marshalFieldMask(m protoreflect.Message) error {
fd := m.Descriptor().Fields().ByNumber(genid.FieldMask_Paths_field_number)
list := m.Get(fd).List()
paths := make([]string, 0, list.Len())
for i := 0; i < list.Len(); i++ {
s := list.Get(i).String()
- if !pref.FullName(s).IsValid() {
+ if !protoreflect.FullName(s).IsValid() {
return errors.New("%s contains invalid path: %q", genid.FieldMask_Paths_field_fullname, s)
}
// Return error if conversion to camelCase is not reversible.
@@ -861,7 +861,7 @@ func (e encoder) marshalFieldMask(m pref.Message) error {
return nil
}
-func (d decoder) unmarshalFieldMask(m pref.Message) error {
+func (d decoder) unmarshalFieldMask(m protoreflect.Message) error {
tok, err := d.Read()
if err != nil {
return err
@@ -880,10 +880,10 @@ func (d decoder) unmarshalFieldMask(m pref.Message) error {
for _, s0 := range paths {
s := strs.JSONSnakeCase(s0)
- if strings.Contains(s0, "_") || !pref.FullName(s).IsValid() {
+ if strings.Contains(s0, "_") || !protoreflect.FullName(s).IsValid() {
return d.newError(tok.Pos(), "%v contains invalid path: %q", genid.FieldMask_Paths_field_fullname, s0)
}
- list.Append(pref.ValueOfString(s))
+ list.Append(protoreflect.ValueOfString(s))
}
return nil
}
diff --git a/encoding/prototext/decode.go b/encoding/prototext/decode.go
index 179d6e8f..4921b2d4 100644
--- a/encoding/prototext/decode.go
+++ b/encoding/prototext/decode.go
@@ -17,7 +17,7 @@ import (
"google.golang.org/protobuf/internal/set"
"google.golang.org/protobuf/internal/strs"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
)
@@ -103,7 +103,7 @@ func (d decoder) syntaxError(pos int, f string, x ...interface{}) error {
}
// unmarshalMessage unmarshals into the given protoreflect.Message.
-func (d decoder) unmarshalMessage(m pref.Message, checkDelims bool) error {
+func (d decoder) unmarshalMessage(m protoreflect.Message, checkDelims bool) error {
messageDesc := m.Descriptor()
if !flags.ProtoLegacy && messageset.IsMessageSet(messageDesc) {
return errors.New("no support for proto1 MessageSets")
@@ -150,24 +150,24 @@ func (d decoder) unmarshalMessage(m pref.Message, checkDelims bool) error {
}
// Resolve the field descriptor.
- var name pref.Name
- var fd pref.FieldDescriptor
- var xt pref.ExtensionType
+ var name protoreflect.Name
+ var fd protoreflect.FieldDescriptor
+ var xt protoreflect.ExtensionType
var xtErr error
var isFieldNumberName bool
switch tok.NameKind() {
case text.IdentName:
- name = pref.Name(tok.IdentName())
+ name = protoreflect.Name(tok.IdentName())
fd = fieldDescs.ByTextName(string(name))
case text.TypeName:
// Handle extensions only. This code path is not for Any.
- xt, xtErr = d.opts.Resolver.FindExtensionByName(pref.FullName(tok.TypeName()))
+ xt, xtErr = d.opts.Resolver.FindExtensionByName(protoreflect.FullName(tok.TypeName()))
case text.FieldNumber:
isFieldNumberName = true
- num := pref.FieldNumber(tok.FieldNumber())
+ num := protoreflect.FieldNumber(tok.FieldNumber())
if !num.IsValid() {
return d.newError(tok.Pos(), "invalid field number: %d", num)
}
@@ -215,7 +215,7 @@ func (d decoder) unmarshalMessage(m pref.Message, checkDelims bool) error {
switch {
case fd.IsList():
kind := fd.Kind()
- if kind != pref.MessageKind && kind != pref.GroupKind && !tok.HasSeparator() {
+ if kind != protoreflect.MessageKind && kind != protoreflect.GroupKind && !tok.HasSeparator() {
return d.syntaxError(tok.Pos(), "missing field separator :")
}
@@ -232,7 +232,7 @@ func (d decoder) unmarshalMessage(m pref.Message, checkDelims bool) error {
default:
kind := fd.Kind()
- if kind != pref.MessageKind && kind != pref.GroupKind && !tok.HasSeparator() {
+ if kind != protoreflect.MessageKind && kind != protoreflect.GroupKind && !tok.HasSeparator() {
return d.syntaxError(tok.Pos(), "missing field separator :")
}
@@ -262,11 +262,11 @@ func (d decoder) unmarshalMessage(m pref.Message, checkDelims bool) error {
// unmarshalSingular unmarshals a non-repeated field value specified by the
// given FieldDescriptor.
-func (d decoder) unmarshalSingular(fd pref.FieldDescriptor, m pref.Message) error {
- var val pref.Value
+func (d decoder) unmarshalSingular(fd protoreflect.FieldDescriptor, m protoreflect.Message) error {
+ var val protoreflect.Value
var err error
switch fd.Kind() {
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
val = m.NewField(fd)
err = d.unmarshalMessage(val.Message(), true)
default:
@@ -280,94 +280,94 @@ func (d decoder) unmarshalSingular(fd pref.FieldDescriptor, m pref.Message) erro
// unmarshalScalar unmarshals a scalar/enum protoreflect.Value specified by the
// given FieldDescriptor.
-func (d decoder) unmarshalScalar(fd pref.FieldDescriptor) (pref.Value, error) {
+func (d decoder) unmarshalScalar(fd protoreflect.FieldDescriptor) (protoreflect.Value, error) {
tok, err := d.Read()
if err != nil {
- return pref.Value{}, err
+ return protoreflect.Value{}, err
}
if tok.Kind() != text.Scalar {
- return pref.Value{}, d.unexpectedTokenError(tok)
+ return protoreflect.Value{}, d.unexpectedTokenError(tok)
}
kind := fd.Kind()
switch kind {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
if b, ok := tok.Bool(); ok {
- return pref.ValueOfBool(b), nil
+ return protoreflect.ValueOfBool(b), nil
}
- case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
if n, ok := tok.Int32(); ok {
- return pref.ValueOfInt32(n), nil
+ return protoreflect.ValueOfInt32(n), nil
}
- case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
+ case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
if n, ok := tok.Int64(); ok {
- return pref.ValueOfInt64(n), nil
+ return protoreflect.ValueOfInt64(n), nil
}
- case pref.Uint32Kind, pref.Fixed32Kind:
+ case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
if n, ok := tok.Uint32(); ok {
- return pref.ValueOfUint32(n), nil
+ return protoreflect.ValueOfUint32(n), nil
}
- case pref.Uint64Kind, pref.Fixed64Kind:
+ case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
if n, ok := tok.Uint64(); ok {
- return pref.ValueOfUint64(n), nil
+ return protoreflect.ValueOfUint64(n), nil
}
- case pref.FloatKind:
+ case protoreflect.FloatKind:
if n, ok := tok.Float32(); ok {
- return pref.ValueOfFloat32(n), nil
+ return protoreflect.ValueOfFloat32(n), nil
}
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
if n, ok := tok.Float64(); ok {
- return pref.ValueOfFloat64(n), nil
+ return protoreflect.ValueOfFloat64(n), nil
}
- case pref.StringKind:
+ case protoreflect.StringKind:
if s, ok := tok.String(); ok {
if strs.EnforceUTF8(fd) && !utf8.ValidString(s) {
- return pref.Value{}, d.newError(tok.Pos(), "contains invalid UTF-8")
+ return protoreflect.Value{}, d.newError(tok.Pos(), "contains invalid UTF-8")
}
- return pref.ValueOfString(s), nil
+ return protoreflect.ValueOfString(s), nil
}
- case pref.BytesKind:
+ case protoreflect.BytesKind:
if b, ok := tok.String(); ok {
- return pref.ValueOfBytes([]byte(b)), nil
+ return protoreflect.ValueOfBytes([]byte(b)), nil
}
- case pref.EnumKind:
+ case protoreflect.EnumKind:
if lit, ok := tok.Enum(); ok {
// Lookup EnumNumber based on name.
- if enumVal := fd.Enum().Values().ByName(pref.Name(lit)); enumVal != nil {
- return pref.ValueOfEnum(enumVal.Number()), nil
+ if enumVal := fd.Enum().Values().ByName(protoreflect.Name(lit)); enumVal != nil {
+ return protoreflect.ValueOfEnum(enumVal.Number()), nil
}
}
if num, ok := tok.Int32(); ok {
- return pref.ValueOfEnum(pref.EnumNumber(num)), nil
+ return protoreflect.ValueOfEnum(protoreflect.EnumNumber(num)), nil
}
default:
panic(fmt.Sprintf("invalid scalar kind %v", kind))
}
- return pref.Value{}, d.newError(tok.Pos(), "invalid value for %v type: %v", kind, tok.RawString())
+ return protoreflect.Value{}, d.newError(tok.Pos(), "invalid value for %v type: %v", kind, tok.RawString())
}
// unmarshalList unmarshals into given protoreflect.List. A list value can
// either be in [] syntax or simply just a single scalar/message value.
-func (d decoder) unmarshalList(fd pref.FieldDescriptor, list pref.List) error {
+func (d decoder) unmarshalList(fd protoreflect.FieldDescriptor, list protoreflect.List) error {
tok, err := d.Peek()
if err != nil {
return err
}
switch fd.Kind() {
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
switch tok.Kind() {
case text.ListOpen:
d.Read()
@@ -441,22 +441,22 @@ func (d decoder) unmarshalList(fd pref.FieldDescriptor, list pref.List) error {
// unmarshalMap unmarshals into given protoreflect.Map. A map value is a
// textproto message containing {key: <kvalue>, value: <mvalue>}.
-func (d decoder) unmarshalMap(fd pref.FieldDescriptor, mmap pref.Map) error {
+func (d decoder) unmarshalMap(fd protoreflect.FieldDescriptor, mmap protoreflect.Map) error {
// Determine ahead whether map entry is a scalar type or a message type in
// order to call the appropriate unmarshalMapValue func inside
// unmarshalMapEntry.
- var unmarshalMapValue func() (pref.Value, error)
+ var unmarshalMapValue func() (protoreflect.Value, error)
switch fd.MapValue().Kind() {
- case pref.MessageKind, pref.GroupKind:
- unmarshalMapValue = func() (pref.Value, error) {
+ case protoreflect.MessageKind, protoreflect.GroupKind:
+ unmarshalMapValue = func() (protoreflect.Value, error) {
pval := mmap.NewValue()
if err := d.unmarshalMessage(pval.Message(), true); err != nil {
- return pref.Value{}, err
+ return protoreflect.Value{}, err
}
return pval, nil
}
default:
- unmarshalMapValue = func() (pref.Value, error) {
+ unmarshalMapValue = func() (protoreflect.Value, error) {
return d.unmarshalScalar(fd.MapValue())
}
}
@@ -494,9 +494,9 @@ func (d decoder) unmarshalMap(fd pref.FieldDescriptor, mmap pref.Map) error {
// unmarshalMap unmarshals into given protoreflect.Map. A map value is a
// textproto message containing {key: <kvalue>, value: <mvalue>}.
-func (d decoder) unmarshalMapEntry(fd pref.FieldDescriptor, mmap pref.Map, unmarshalMapValue func() (pref.Value, error)) error {
- var key pref.MapKey
- var pval pref.Value
+func (d decoder) unmarshalMapEntry(fd protoreflect.FieldDescriptor, mmap protoreflect.Map, unmarshalMapValue func() (protoreflect.Value, error)) error {
+ var key protoreflect.MapKey
+ var pval protoreflect.Value
Loop:
for {
// Read field name.
@@ -520,7 +520,7 @@ Loop:
return d.unexpectedTokenError(tok)
}
- switch name := pref.Name(tok.IdentName()); name {
+ switch name := protoreflect.Name(tok.IdentName()); name {
case genid.MapEntry_Key_field_name:
if !tok.HasSeparator() {
return d.syntaxError(tok.Pos(), "missing field separator :")
@@ -535,7 +535,7 @@ Loop:
key = val.MapKey()
case genid.MapEntry_Value_field_name:
- if kind := fd.MapValue().Kind(); (kind != pref.MessageKind) && (kind != pref.GroupKind) {
+ if kind := fd.MapValue().Kind(); (kind != protoreflect.MessageKind) && (kind != protoreflect.GroupKind) {
if !tok.HasSeparator() {
return d.syntaxError(tok.Pos(), "missing field separator :")
}
@@ -561,7 +561,7 @@ Loop:
}
if !pval.IsValid() {
switch fd.MapValue().Kind() {
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
// If value field is not set for message/group types, construct an
// empty one as default.
pval = mmap.NewValue()
@@ -575,7 +575,7 @@ Loop:
// unmarshalAny unmarshals an Any textproto. It can either be in expanded form
// or non-expanded form.
-func (d decoder) unmarshalAny(m pref.Message, checkDelims bool) error {
+func (d decoder) unmarshalAny(m protoreflect.Message, checkDelims bool) error {
var typeURL string
var bValue []byte
var seenTypeUrl bool
@@ -619,7 +619,7 @@ Loop:
return d.syntaxError(tok.Pos(), "missing field separator :")
}
- switch name := pref.Name(tok.IdentName()); name {
+ switch name := protoreflect.Name(tok.IdentName()); name {
case genid.Any_TypeUrl_field_name:
if seenTypeUrl {
return d.newError(tok.Pos(), "duplicate %v field", genid.Any_TypeUrl_field_fullname)
@@ -686,10 +686,10 @@ Loop:
fds := m.Descriptor().Fields()
if len(typeURL) > 0 {
- m.Set(fds.ByNumber(genid.Any_TypeUrl_field_number), pref.ValueOfString(typeURL))
+ m.Set(fds.ByNumber(genid.Any_TypeUrl_field_number), protoreflect.ValueOfString(typeURL))
}
if len(bValue) > 0 {
- m.Set(fds.ByNumber(genid.Any_Value_field_number), pref.ValueOfBytes(bValue))
+ m.Set(fds.ByNumber(genid.Any_Value_field_number), protoreflect.ValueOfBytes(bValue))
}
return nil
}
diff --git a/encoding/prototext/decode_test.go b/encoding/prototext/decode_test.go
index 2e92dd20..eed64dbf 100644
--- a/encoding/prototext/decode_test.go
+++ b/encoding/prototext/decode_test.go
@@ -12,7 +12,7 @@ import (
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/proto"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protoregistry"
testpb "google.golang.org/protobuf/internal/testprotos/test"
weakpb "google.golang.org/protobuf/internal/testprotos/test/weak1"
@@ -1630,7 +1630,7 @@ value: "some bytes"
wantErr: "contains invalid UTF-8",
}, {
desc: "Any expanded with unregistered type",
- umo: prototext.UnmarshalOptions{Resolver: new(preg.Types)},
+ umo: prototext.UnmarshalOptions{Resolver: new(protoregistry.Types)},
inputMessage: &anypb.Any{},
inputText: `[SomeMessage]: {}`,
wantErr: "unable to resolve message [SomeMessage]",
diff --git a/encoding/prototext/encode_test.go b/encoding/prototext/encode_test.go
index 49fba142..96510bce 100644
--- a/encoding/prototext/encode_test.go
+++ b/encoding/prototext/encode_test.go
@@ -14,7 +14,7 @@ import (
"google.golang.org/protobuf/internal/detrand"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/proto"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/testing/protopack"
pb2 "google.golang.org/protobuf/internal/testprotos/textpb2"
@@ -1200,7 +1200,7 @@ opt_int32: 42
}, {
desc: "Any not expanded",
mo: prototext.MarshalOptions{
- Resolver: new(preg.Types),
+ Resolver: new(protoregistry.Types),
},
input: func() proto.Message {
m := &pb2.Nested{
diff --git a/encoding/prototext/other_test.go b/encoding/prototext/other_test.go
index cb0f35f4..5cebffdc 100644
--- a/encoding/prototext/other_test.go
+++ b/encoding/prototext/other_test.go
@@ -9,7 +9,7 @@ import (
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protoregistry"
pb2 "google.golang.org/protobuf/internal/testprotos/textpb2"
"google.golang.org/protobuf/types/known/anypb"
@@ -23,7 +23,7 @@ import (
func TestRoundTrip(t *testing.T) {
tests := []struct {
desc string
- resolver *preg.Types
+ resolver *protoregistry.Types
message proto.Message
}{{
desc: "well-known type fields set to empty messages",
@@ -149,7 +149,7 @@ func TestRoundTrip(t *testing.T) {
},
}, {
desc: "Any field without registered type",
- resolver: new(preg.Types),
+ resolver: new(protoregistry.Types),
message: func() proto.Message {
m := &pb2.Nested{
OptString: proto.String("embedded inside Any"),
diff --git a/internal/benchmarks/bench_test.go b/internal/benchmarks/bench_test.go
index 33b18fca..2bf2b981 100644
--- a/internal/benchmarks/bench_test.go
+++ b/internal/benchmarks/bench_test.go
@@ -18,8 +18,8 @@ import (
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoregistry"
benchpb "google.golang.org/protobuf/internal/testprotos/benchmarks"
_ "google.golang.org/protobuf/internal/testprotos/benchmarks/datasets/google_message1/proto2"
@@ -127,7 +127,7 @@ func bench(b *testing.B, name string, f func(dataset, *testing.PB)) {
type dataset struct {
name string
- messageType pref.MessageType
+ messageType protoreflect.MessageType
messages []proto.Message
wire [][]byte
text [][]byte
@@ -183,7 +183,7 @@ func TestMain(m *testing.M) {
if err := proto.Unmarshal(raw, dspb); err != nil {
panic(err)
}
- mt, err := preg.GlobalTypes.FindMessageByName(pref.FullName(dspb.MessageName))
+ mt, err := protoregistry.GlobalTypes.FindMessageByName(protoreflect.FullName(dspb.MessageName))
if err != nil {
panic(err)
}
diff --git a/internal/cmd/pbdump/pbdump_test.go b/internal/cmd/pbdump/pbdump_test.go
index 567cea0e..9f9bd5aa 100644
--- a/internal/cmd/pbdump/pbdump_test.go
+++ b/internal/cmd/pbdump/pbdump_test.go
@@ -11,7 +11,7 @@ import (
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/descriptorpb"
)
@@ -27,7 +27,7 @@ func mustMakeMessage(s string) *descriptorpb.DescriptorProto {
func TestFields(t *testing.T) {
type fieldsKind struct {
- kind pref.Kind
+ kind protoreflect.Kind
fields string
}
tests := []struct {
@@ -35,31 +35,31 @@ func TestFields(t *testing.T) {
wantMsg *descriptorpb.DescriptorProto
wantErr string
}{{
- inFields: []fieldsKind{{pref.MessageKind, ""}},
+ inFields: []fieldsKind{{protoreflect.MessageKind, ""}},
wantMsg: mustMakeMessage(`name:"X"`),
}, {
- inFields: []fieldsKind{{pref.MessageKind, "987654321"}},
+ inFields: []fieldsKind{{protoreflect.MessageKind, "987654321"}},
wantErr: "invalid field: 987654321",
}, {
- inFields: []fieldsKind{{pref.MessageKind, "-1"}},
+ inFields: []fieldsKind{{protoreflect.MessageKind, "-1"}},
wantErr: "invalid field: -1",
}, {
- inFields: []fieldsKind{{pref.MessageKind, "k"}},
+ inFields: []fieldsKind{{protoreflect.MessageKind, "k"}},
wantErr: "invalid field: k",
}, {
- inFields: []fieldsKind{{pref.MessageKind, "1.2"}, {pref.Int32Kind, "1"}},
+ inFields: []fieldsKind{{protoreflect.MessageKind, "1.2"}, {protoreflect.Int32Kind, "1"}},
wantErr: "field 1 of int32 type cannot have sub-fields",
}, {
- inFields: []fieldsKind{{pref.Int32Kind, "1"}, {pref.MessageKind, "1.2"}},
+ inFields: []fieldsKind{{protoreflect.Int32Kind, "1"}, {protoreflect.MessageKind, "1.2"}},
wantErr: "field 1 of int32 type cannot have sub-fields",
}, {
- inFields: []fieldsKind{{pref.Int32Kind, "30"}, {pref.Int32Kind, "30"}},
+ inFields: []fieldsKind{{protoreflect.Int32Kind, "30"}, {protoreflect.Int32Kind, "30"}},
wantErr: "field 30 already set as int32 type",
}, {
inFields: []fieldsKind{
- {pref.Int32Kind, "10.20.31"},
- {pref.MessageKind, " 10.20.30, 10.21 "},
- {pref.GroupKind, "10"},
+ {protoreflect.Int32Kind, "10.20.31"},
+ {protoreflect.MessageKind, " 10.20.30, 10.21 "},
+ {protoreflect.GroupKind, "10"},
},
wantMsg: mustMakeMessage(`
name: "X"
diff --git a/internal/descfmt/stringer.go b/internal/descfmt/stringer.go
index 360c6332..db5248e1 100644
--- a/internal/descfmt/stringer.go
+++ b/internal/descfmt/stringer.go
@@ -14,7 +14,7 @@ import (
"google.golang.org/protobuf/internal/detrand"
"google.golang.org/protobuf/internal/pragma"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
type list interface {
@@ -30,17 +30,17 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
if isRoot {
var name string
switch vs.(type) {
- case pref.Names:
+ case protoreflect.Names:
name = "Names"
- case pref.FieldNumbers:
+ case protoreflect.FieldNumbers:
name = "FieldNumbers"
- case pref.FieldRanges:
+ case protoreflect.FieldRanges:
name = "FieldRanges"
- case pref.EnumRanges:
+ case protoreflect.EnumRanges:
name = "EnumRanges"
- case pref.FileImports:
+ case protoreflect.FileImports:
name = "FileImports"
- case pref.Descriptor:
+ case protoreflect.Descriptor:
name = reflect.ValueOf(vs).MethodByName("Get").Type().Out(0).Name() + "s"
default:
name = reflect.ValueOf(vs).Elem().Type().Name()
@@ -50,17 +50,17 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
var ss []string
switch vs := vs.(type) {
- case pref.Names:
+ case protoreflect.Names:
for i := 0; i < vs.Len(); i++ {
ss = append(ss, fmt.Sprint(vs.Get(i)))
}
return start + joinStrings(ss, false) + end
- case pref.FieldNumbers:
+ case protoreflect.FieldNumbers:
for i := 0; i < vs.Len(); i++ {
ss = append(ss, fmt.Sprint(vs.Get(i)))
}
return start + joinStrings(ss, false) + end
- case pref.FieldRanges:
+ case protoreflect.FieldRanges:
for i := 0; i < vs.Len(); i++ {
r := vs.Get(i)
if r[0]+1 == r[1] {
@@ -70,7 +70,7 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
}
}
return start + joinStrings(ss, false) + end
- case pref.EnumRanges:
+ case protoreflect.EnumRanges:
for i := 0; i < vs.Len(); i++ {
r := vs.Get(i)
if r[0] == r[1] {
@@ -80,7 +80,7 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
}
}
return start + joinStrings(ss, false) + end
- case pref.FileImports:
+ case protoreflect.FileImports:
for i := 0; i < vs.Len(); i++ {
var rs records
rs.Append(reflect.ValueOf(vs.Get(i)), "Path", "Package", "IsPublic", "IsWeak")
@@ -88,11 +88,11 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
}
return start + joinStrings(ss, allowMulti) + end
default:
- _, isEnumValue := vs.(pref.EnumValueDescriptors)
+ _, isEnumValue := vs.(protoreflect.EnumValueDescriptors)
for i := 0; i < vs.Len(); i++ {
m := reflect.ValueOf(vs).MethodByName("Get")
v := m.Call([]reflect.Value{reflect.ValueOf(i)})[0].Interface()
- ss = append(ss, formatDescOpt(v.(pref.Descriptor), false, allowMulti && !isEnumValue))
+ ss = append(ss, formatDescOpt(v.(protoreflect.Descriptor), false, allowMulti && !isEnumValue))
}
return start + joinStrings(ss, allowMulti && isEnumValue) + end
}
@@ -106,20 +106,20 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
//
// Using a list allows us to print the accessors in a sensible order.
var descriptorAccessors = map[reflect.Type][]string{
- reflect.TypeOf((*pref.FileDescriptor)(nil)).Elem(): {"Path", "Package", "Imports", "Messages", "Enums", "Extensions", "Services"},
- reflect.TypeOf((*pref.MessageDescriptor)(nil)).Elem(): {"IsMapEntry", "Fields", "Oneofs", "ReservedNames", "ReservedRanges", "RequiredNumbers", "ExtensionRanges", "Messages", "Enums", "Extensions"},
- reflect.TypeOf((*pref.FieldDescriptor)(nil)).Elem(): {"Number", "Cardinality", "Kind", "HasJSONName", "JSONName", "HasPresence", "IsExtension", "IsPacked", "IsWeak", "IsList", "IsMap", "MapKey", "MapValue", "HasDefault", "Default", "ContainingOneof", "ContainingMessage", "Message", "Enum"},
- reflect.TypeOf((*pref.OneofDescriptor)(nil)).Elem(): {"Fields"}, // not directly used; must keep in sync with formatDescOpt
- reflect.TypeOf((*pref.EnumDescriptor)(nil)).Elem(): {"Values", "ReservedNames", "ReservedRanges"},
- reflect.TypeOf((*pref.EnumValueDescriptor)(nil)).Elem(): {"Number"},
- reflect.TypeOf((*pref.ServiceDescriptor)(nil)).Elem(): {"Methods"},
- reflect.TypeOf((*pref.MethodDescriptor)(nil)).Elem(): {"Input", "Output", "IsStreamingClient", "IsStreamingServer"},
+ reflect.TypeOf((*protoreflect.FileDescriptor)(nil)).Elem(): {"Path", "Package", "Imports", "Messages", "Enums", "Extensions", "Services"},
+ reflect.TypeOf((*protoreflect.MessageDescriptor)(nil)).Elem(): {"IsMapEntry", "Fields", "Oneofs", "ReservedNames", "ReservedRanges", "RequiredNumbers", "ExtensionRanges", "Messages", "Enums", "Extensions"},
+ reflect.TypeOf((*protoreflect.FieldDescriptor)(nil)).Elem(): {"Number", "Cardinality", "Kind", "HasJSONName", "JSONName", "HasPresence", "IsExtension", "IsPacked", "IsWeak", "IsList", "IsMap", "MapKey", "MapValue", "HasDefault", "Default", "ContainingOneof", "ContainingMessage", "Message", "Enum"},
+ reflect.TypeOf((*protoreflect.OneofDescriptor)(nil)).Elem(): {"Fields"}, // not directly used; must keep in sync with formatDescOpt
+ reflect.TypeOf((*protoreflect.EnumDescriptor)(nil)).Elem(): {"Values", "ReservedNames", "ReservedRanges"},
+ reflect.TypeOf((*protoreflect.EnumValueDescriptor)(nil)).Elem(): {"Number"},
+ reflect.TypeOf((*protoreflect.ServiceDescriptor)(nil)).Elem(): {"Methods"},
+ reflect.TypeOf((*protoreflect.MethodDescriptor)(nil)).Elem(): {"Input", "Output", "IsStreamingClient", "IsStreamingServer"},
}
-func FormatDesc(s fmt.State, r rune, t pref.Descriptor) {
+func FormatDesc(s fmt.State, r rune, t protoreflect.Descriptor) {
io.WriteString(s, formatDescOpt(t, true, r == 'v' && (s.Flag('+') || s.Flag('#'))))
}
-func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
+func formatDescOpt(t protoreflect.Descriptor, isRoot, allowMulti bool) string {
rv := reflect.ValueOf(t)
rt := rv.MethodByName("ProtoType").Type().In(0)
@@ -128,7 +128,7 @@ func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
start = rt.Name() + "{"
}
- _, isFile := t.(pref.FileDescriptor)
+ _, isFile := t.(protoreflect.FileDescriptor)
rs := records{allowMulti: allowMulti}
if t.IsPlaceholder() {
if isFile {
@@ -146,7 +146,7 @@ func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
rs.Append(rv, "Name")
}
switch t := t.(type) {
- case pref.FieldDescriptor:
+ case protoreflect.FieldDescriptor:
for _, s := range descriptorAccessors[rt] {
switch s {
case "MapKey":
@@ -156,9 +156,9 @@ func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
case "MapValue":
if v := t.MapValue(); v != nil {
switch v.Kind() {
- case pref.EnumKind:
+ case protoreflect.EnumKind:
rs.recs = append(rs.recs, [2]string{"MapValue", string(v.Enum().FullName())})
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
rs.recs = append(rs.recs, [2]string{"MapValue", string(v.Message().FullName())})
default:
rs.recs = append(rs.recs, [2]string{"MapValue", v.Kind().String()})
@@ -180,7 +180,7 @@ func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
rs.Append(rv, s)
}
}
- case pref.OneofDescriptor:
+ case protoreflect.OneofDescriptor:
var ss []string
fs := t.Fields()
for i := 0; i < fs.Len(); i++ {
@@ -216,7 +216,7 @@ func (rs *records) Append(v reflect.Value, accessors ...string) {
if !rv.IsValid() {
panic(fmt.Sprintf("unknown accessor: %v.%s", v.Type(), a))
}
- if _, ok := rv.Interface().(pref.Value); ok {
+ if _, ok := rv.Interface().(protoreflect.Value); ok {
rv = rv.MethodByName("Interface").Call(nil)[0]
if !rv.IsNil() {
rv = rv.Elem()
@@ -250,9 +250,9 @@ func (rs *records) Append(v reflect.Value, accessors ...string) {
switch v := v.(type) {
case list:
s = formatListOpt(v, false, rs.allowMulti)
- case pref.FieldDescriptor, pref.OneofDescriptor, pref.EnumValueDescriptor, pref.MethodDescriptor:
- s = string(v.(pref.Descriptor).Name())
- case pref.Descriptor:
+ case protoreflect.FieldDescriptor, protoreflect.OneofDescriptor, protoreflect.EnumValueDescriptor, protoreflect.MethodDescriptor:
+ s = string(v.(protoreflect.Descriptor).Name())
+ case protoreflect.Descriptor:
s = string(v.FullName())
case string:
s = strconv.Quote(v)
diff --git a/internal/encoding/defval/default.go b/internal/encoding/defval/default.go
index fdd9b13f..328dc733 100644
--- a/internal/encoding/defval/default.go
+++ b/internal/encoding/defval/default.go
@@ -15,8 +15,8 @@ import (
"strconv"
ptext "google.golang.org/protobuf/internal/encoding/text"
- errors "google.golang.org/protobuf/internal/errors"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/internal/errors"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
// Format is the serialization format used to represent the default value.
@@ -35,56 +35,56 @@ const (
// Unmarshal deserializes the default string s according to the given kind k.
// When k is an enum, a list of enum value descriptors must be provided.
-func Unmarshal(s string, k pref.Kind, evs pref.EnumValueDescriptors, f Format) (pref.Value, pref.EnumValueDescriptor, error) {
+func Unmarshal(s string, k protoreflect.Kind, evs protoreflect.EnumValueDescriptors, f Format) (protoreflect.Value, protoreflect.EnumValueDescriptor, error) {
switch k {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
if f == GoTag {
switch s {
case "1":
- return pref.ValueOfBool(true), nil, nil
+ return protoreflect.ValueOfBool(true), nil, nil
case "0":
- return pref.ValueOfBool(false), nil, nil
+ return protoreflect.ValueOfBool(false), nil, nil
}
} else {
switch s {
case "true":
- return pref.ValueOfBool(true), nil, nil
+ return protoreflect.ValueOfBool(true), nil, nil
case "false":
- return pref.ValueOfBool(false), nil, nil
+ return protoreflect.ValueOfBool(false), nil, nil
}
}
- case pref.EnumKind:
+ case protoreflect.EnumKind:
if f == GoTag {
// Go tags use the numeric form of the enum value.
if n, err := strconv.ParseInt(s, 10, 32); err == nil {
- if ev := evs.ByNumber(pref.EnumNumber(n)); ev != nil {
- return pref.ValueOfEnum(ev.Number()), ev, nil
+ if ev := evs.ByNumber(protoreflect.EnumNumber(n)); ev != nil {
+ return protoreflect.ValueOfEnum(ev.Number()), ev, nil
}
}
} else {
// Descriptor default_value use the enum identifier.
- ev := evs.ByName(pref.Name(s))
+ ev := evs.ByName(protoreflect.Name(s))
if ev != nil {
- return pref.ValueOfEnum(ev.Number()), ev, nil
+ return protoreflect.ValueOfEnum(ev.Number()), ev, nil
}
}
- case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
if v, err := strconv.ParseInt(s, 10, 32); err == nil {
- return pref.ValueOfInt32(int32(v)), nil, nil
+ return protoreflect.ValueOfInt32(int32(v)), nil, nil
}
- case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
+ case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
if v, err := strconv.ParseInt(s, 10, 64); err == nil {
- return pref.ValueOfInt64(int64(v)), nil, nil
+ return protoreflect.ValueOfInt64(int64(v)), nil, nil
}
- case pref.Uint32Kind, pref.Fixed32Kind:
+ case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
if v, err := strconv.ParseUint(s, 10, 32); err == nil {
- return pref.ValueOfUint32(uint32(v)), nil, nil
+ return protoreflect.ValueOfUint32(uint32(v)), nil, nil
}
- case pref.Uint64Kind, pref.Fixed64Kind:
+ case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
if v, err := strconv.ParseUint(s, 10, 64); err == nil {
- return pref.ValueOfUint64(uint64(v)), nil, nil
+ return protoreflect.ValueOfUint64(uint64(v)), nil, nil
}
- case pref.FloatKind, pref.DoubleKind:
+ case protoreflect.FloatKind, protoreflect.DoubleKind:
var v float64
var err error
switch s {
@@ -98,29 +98,29 @@ func Unmarshal(s string, k pref.Kind, evs pref.EnumValueDescriptors, f Format) (
v, err = strconv.ParseFloat(s, 64)
}
if err == nil {
- if k == pref.FloatKind {
- return pref.ValueOfFloat32(float32(v)), nil, nil
+ if k == protoreflect.FloatKind {
+ return protoreflect.ValueOfFloat32(float32(v)), nil, nil
} else {
- return pref.ValueOfFloat64(float64(v)), nil, nil
+ return protoreflect.ValueOfFloat64(float64(v)), nil, nil
}
}
- case pref.StringKind:
+ case protoreflect.StringKind:
// String values are already unescaped and can be used as is.
- return pref.ValueOfString(s), nil, nil
- case pref.BytesKind:
+ return protoreflect.ValueOfString(s), nil, nil
+ case protoreflect.BytesKind:
if b, ok := unmarshalBytes(s); ok {
- return pref.ValueOfBytes(b), nil, nil
+ return protoreflect.ValueOfBytes(b), nil, nil
}
}
- return pref.Value{}, nil, errors.New("could not parse value for %v: %q", k, s)
+ return protoreflect.Value{}, nil, errors.New("could not parse value for %v: %q", k, s)
}
// Marshal serializes v as the default string according to the given kind k.
// When specifying the Descriptor format for an enum kind, the associated
// enum value descriptor must be provided.
-func Marshal(v pref.Value, ev pref.EnumValueDescriptor, k pref.Kind, f Format) (string, error) {
+func Marshal(v protoreflect.Value, ev protoreflect.EnumValueDescriptor, k protoreflect.Kind, f Format) (string, error) {
switch k {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
if f == GoTag {
if v.Bool() {
return "1", nil
@@ -134,17 +134,17 @@ func Marshal(v pref.Value, ev pref.EnumValueDescriptor, k pref.Kind, f Format) (
return "false", nil
}
}
- case pref.EnumKind:
+ case protoreflect.EnumKind:
if f == GoTag {
return strconv.FormatInt(int64(v.Enum()), 10), nil
} else {
return string(ev.Name()), nil
}
- case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind, pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
return strconv.FormatInt(v.Int(), 10), nil
- case pref.Uint32Kind, pref.Fixed32Kind, pref.Uint64Kind, pref.Fixed64Kind:
+ case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
return strconv.FormatUint(v.Uint(), 10), nil
- case pref.FloatKind, pref.DoubleKind:
+ case protoreflect.FloatKind, protoreflect.DoubleKind:
f := v.Float()
switch {
case math.IsInf(f, -1):
@@ -154,16 +154,16 @@ func Marshal(v pref.Value, ev pref.EnumValueDescriptor, k pref.Kind, f Format) (
case math.IsNaN(f):
return "nan", nil
default:
- if k == pref.FloatKind {
+ if k == protoreflect.FloatKind {
return strconv.FormatFloat(f, 'g', -1, 32), nil
} else {
return strconv.FormatFloat(f, 'g', -1, 64), nil
}
}
- case pref.StringKind:
+ case protoreflect.StringKind:
// String values are serialized as is without any escaping.
return v.String(), nil
- case pref.BytesKind:
+ case protoreflect.BytesKind:
if s, ok := marshalBytes(v.Bytes()); ok {
return s, nil
}
diff --git a/internal/encoding/defval/default_test.go b/internal/encoding/defval/default_test.go
index d81150d7..bde8ca2a 100644
--- a/internal/encoding/defval/default_test.go
+++ b/internal/encoding/defval/default_test.go
@@ -10,71 +10,71 @@ import (
"testing"
"google.golang.org/protobuf/internal/encoding/defval"
- fdesc "google.golang.org/protobuf/internal/filedesc"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/internal/filedesc"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
func Test(t *testing.T) {
- evs := fdesc.EnumValues{List: []fdesc.EnumValue{{}}}
- evs.List[0].L0.ParentFile = fdesc.SurrogateProto2
+ evs := filedesc.EnumValues{List: []filedesc.EnumValue{{}}}
+ evs.List[0].L0.ParentFile = filedesc.SurrogateProto2
evs.List[0].L0.FullName = "ALPHA"
evs.List[0].L1.Number = 1
- V := pref.ValueOf
+ V := protoreflect.ValueOf
tests := []struct {
- val pref.Value
- enum pref.EnumValueDescriptor
- enums pref.EnumValueDescriptors
- kind pref.Kind
+ val protoreflect.Value
+ enum protoreflect.EnumValueDescriptor
+ enums protoreflect.EnumValueDescriptors
+ kind protoreflect.Kind
strPB string
strGo string
}{{
val: V(bool(true)),
enum: nil,
enums: nil,
- kind: pref.BoolKind,
+ kind: protoreflect.BoolKind,
strPB: "true",
strGo: "1",
}, {
val: V(int32(-0x1234)),
enum: nil,
enums: nil,
- kind: pref.Int32Kind,
+ kind: protoreflect.Int32Kind,
strPB: "-4660",
strGo: "-4660",
}, {
val: V(float32(math.Pi)),
enum: nil,
enums: nil,
- kind: pref.FloatKind,
+ kind: protoreflect.FloatKind,
strPB: "3.1415927",
strGo: "3.1415927",
}, {
val: V(float64(math.Pi)),
enum: nil,
enums: nil,
- kind: pref.DoubleKind,
+ kind: protoreflect.DoubleKind,
strPB: "3.141592653589793",
strGo: "3.141592653589793",
}, {
val: V(string("hello, \xde\xad\xbe\xef\n")),
enum: nil,
enums: nil,
- kind: pref.StringKind,
+ kind: protoreflect.StringKind,
strPB: "hello, \xde\xad\xbe\xef\n",
strGo: "hello, \xde\xad\xbe\xef\n",
}, {
val: V([]byte("hello, \xde\xad\xbe\xef\n")),
enum: nil,
enums: nil,
- kind: pref.BytesKind,
+ kind: protoreflect.BytesKind,
strPB: "hello, \\336\\255\\276\\357\\n",
strGo: "hello, \\336\\255\\276\\357\\n",
}, {
- val: V(pref.EnumNumber(1)),
+ val: V(protoreflect.EnumNumber(1)),
enum: &evs.List[0],
enums: &evs,
- kind: pref.EnumKind,
+ kind: protoreflect.EnumKind,
strPB: "ALPHA",
strGo: "1",
}}
diff --git a/internal/encoding/messageset/messageset.go b/internal/encoding/messageset/messageset.go
index c1866f3c..ef6d498e 100644
--- a/internal/encoding/messageset/messageset.go
+++ b/internal/encoding/messageset/messageset.go
@@ -10,7 +10,7 @@ import (
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/errors"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
// The MessageSet wire format is equivalent to a message defined as follows,
@@ -42,13 +42,13 @@ const (
const ExtensionName = "message_set_extension"
// IsMessageSet returns whether the message uses the MessageSet wire format.
-func IsMessageSet(md pref.MessageDescriptor) bool {
+func IsMessageSet(md protoreflect.MessageDescriptor) bool {
xmd, ok := md.(interface{ IsMessageSet() bool })
return ok && xmd.IsMessageSet()
}
// IsMessageSetExtension reports this field properly extends a MessageSet.
-func IsMessageSetExtension(fd pref.FieldDescriptor) bool {
+func IsMessageSetExtension(fd protoreflect.FieldDescriptor) bool {
switch {
case fd.Name() != ExtensionName:
return false
diff --git a/internal/encoding/tag/tag.go b/internal/encoding/tag/tag.go
index 38f1931c..373d2083 100644
--- a/internal/encoding/tag/tag.go
+++ b/internal/encoding/tag/tag.go
@@ -11,10 +11,10 @@ import (
"strconv"
"strings"
- defval "google.golang.org/protobuf/internal/encoding/defval"
- fdesc "google.golang.org/protobuf/internal/filedesc"
+ "google.golang.org/protobuf/internal/encoding/defval"
+ "google.golang.org/protobuf/internal/filedesc"
"google.golang.org/protobuf/internal/strs"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
var byteType = reflect.TypeOf(byte(0))
@@ -29,9 +29,9 @@ var byteType = reflect.TypeOf(byte(0))
// This does not populate the Enum or Message (except for weak message).
//
// This function is a best effort attempt; parsing errors are ignored.
-func Unmarshal(tag string, goType reflect.Type, evs pref.EnumValueDescriptors) pref.FieldDescriptor {
- f := new(fdesc.Field)
- f.L0.ParentFile = fdesc.SurrogateProto2
+func Unmarshal(tag string, goType reflect.Type, evs protoreflect.EnumValueDescriptors) protoreflect.FieldDescriptor {
+ f := new(filedesc.Field)
+ f.L0.ParentFile = filedesc.SurrogateProto2
for len(tag) > 0 {
i := strings.IndexByte(tag, ',')
if i < 0 {
@@ -39,68 +39,68 @@ func Unmarshal(tag string, goType reflect.Type, evs pref.EnumValueDescriptors) p
}
switch s := tag[:i]; {
case strings.HasPrefix(s, "name="):
- f.L0.FullName = pref.FullName(s[len("name="):])
+ f.L0.FullName = protoreflect.FullName(s[len("name="):])
case strings.Trim(s, "0123456789") == "":
n, _ := strconv.ParseUint(s, 10, 32)
- f.L1.Number = pref.FieldNumber(n)
+ f.L1.Number = protoreflect.FieldNumber(n)
case s == "opt":
- f.L1.Cardinality = pref.Optional
+ f.L1.Cardinality = protoreflect.Optional
case s == "req":
- f.L1.Cardinality = pref.Required
+ f.L1.Cardinality = protoreflect.Required
case s == "rep":
- f.L1.Cardinality = pref.Repeated
+ f.L1.Cardinality = protoreflect.Repeated
case s == "varint":
switch goType.Kind() {
case reflect.Bool:
- f.L1.Kind = pref.BoolKind
+ f.L1.Kind = protoreflect.BoolKind
case reflect.Int32:
- f.L1.Kind = pref.Int32Kind
+ f.L1.Kind = protoreflect.Int32Kind
case reflect.Int64:
- f.L1.Kind = pref.Int64Kind
+ f.L1.Kind = protoreflect.Int64Kind
case reflect.Uint32:
- f.L1.Kind = pref.Uint32Kind
+ f.L1.Kind = protoreflect.Uint32Kind
case reflect.Uint64:
- f.L1.Kind = pref.Uint64Kind
+ f.L1.Kind = protoreflect.Uint64Kind
}
case s == "zigzag32":
if goType.Kind() == reflect.Int32 {
- f.L1.Kind = pref.Sint32Kind
+ f.L1.Kind = protoreflect.Sint32Kind
}
case s == "zigzag64":
if goType.Kind() == reflect.Int64 {
- f.L1.Kind = pref.Sint64Kind
+ f.L1.Kind = protoreflect.Sint64Kind
}
case s == "fixed32":
switch goType.Kind() {
case reflect.Int32:
- f.L1.Kind = pref.Sfixed32Kind
+ f.L1.Kind = protoreflect.Sfixed32Kind
case reflect.Uint32:
- f.L1.Kind = pref.Fixed32Kind
+ f.L1.Kind = protoreflect.Fixed32Kind
case reflect.Float32:
- f.L1.Kind = pref.FloatKind
+ f.L1.Kind = protoreflect.FloatKind
}
case s == "fixed64":
switch goType.Kind() {
case reflect.Int64:
- f.L1.Kind = pref.Sfixed64Kind
+ f.L1.Kind = protoreflect.Sfixed64Kind
case reflect.Uint64:
- f.L1.Kind = pref.Fixed64Kind
+ f.L1.Kind = protoreflect.Fixed64Kind
case reflect.Float64:
- f.L1.Kind = pref.DoubleKind
+ f.L1.Kind = protoreflect.DoubleKind
}
case s == "bytes":
switch {
case goType.Kind() == reflect.String:
- f.L1.Kind = pref.StringKind
+ f.L1.Kind = protoreflect.StringKind
case goType.Kind() == reflect.Slice && goType.Elem() == byteType:
- f.L1.Kind = pref.BytesKind
+ f.L1.Kind = protoreflect.BytesKind
default:
- f.L1.Kind = pref.MessageKind
+ f.L1.Kind = protoreflect.MessageKind
}
case s == "group":
- f.L1.Kind = pref.GroupKind
+ f.L1.Kind = protoreflect.GroupKind
case strings.HasPrefix(s, "enum="):
- f.L1.Kind = pref.EnumKind
+ f.L1.Kind = protoreflect.EnumKind
case strings.HasPrefix(s, "json="):
jsonName := s[len("json="):]
if jsonName != strs.JSONCamelCase(string(f.L0.FullName.Name())) {
@@ -111,23 +111,23 @@ func Unmarshal(tag string, goType reflect.Type, evs pref.EnumValueDescriptors) p
f.L1.IsPacked = true
case strings.HasPrefix(s, "weak="):
f.L1.IsWeak = true
- f.L1.Message = fdesc.PlaceholderMessage(pref.FullName(s[len("weak="):]))
+ f.L1.Message = filedesc.PlaceholderMessage(protoreflect.FullName(s[len("weak="):]))
case strings.HasPrefix(s, "def="):
// The default tag is special in that everything afterwards is the
// default regardless of the presence of commas.
s, i = tag[len("def="):], len(tag)
v, ev, _ := defval.Unmarshal(s, f.L1.Kind, evs, defval.GoTag)
- f.L1.Default = fdesc.DefaultValue(v, ev)
+ f.L1.Default = filedesc.DefaultValue(v, ev)
case s == "proto3":
- f.L0.ParentFile = fdesc.SurrogateProto3
+ f.L0.ParentFile = filedesc.SurrogateProto3
}
tag = strings.TrimPrefix(tag[i:], ",")
}
// The generator uses the group message name instead of the field name.
// We obtain the real field name by lowercasing the group name.
- if f.L1.Kind == pref.GroupKind {
- f.L0.FullName = pref.FullName(strings.ToLower(string(f.L0.FullName)))
+ if f.L1.Kind == protoreflect.GroupKind {
+ f.L0.FullName = protoreflect.FullName(strings.ToLower(string(f.L0.FullName)))
}
return f
}
@@ -140,38 +140,38 @@ func Unmarshal(tag string, goType reflect.Type, evs pref.EnumValueDescriptors) p
// Depending on the context on how Marshal is called, there are different ways
// through which that information is determined. As such it is the caller's
// responsibility to provide a function to obtain that information.
-func Marshal(fd pref.FieldDescriptor, enumName string) string {
+func Marshal(fd protoreflect.FieldDescriptor, enumName string) string {
var tag []string
switch fd.Kind() {
- case pref.BoolKind, pref.EnumKind, pref.Int32Kind, pref.Uint32Kind, pref.Int64Kind, pref.Uint64Kind:
+ case protoreflect.BoolKind, protoreflect.EnumKind, protoreflect.Int32Kind, protoreflect.Uint32Kind, protoreflect.Int64Kind, protoreflect.Uint64Kind:
tag = append(tag, "varint")
- case pref.Sint32Kind:
+ case protoreflect.Sint32Kind:
tag = append(tag, "zigzag32")
- case pref.Sint64Kind:
+ case protoreflect.Sint64Kind:
tag = append(tag, "zigzag64")
- case pref.Sfixed32Kind, pref.Fixed32Kind, pref.FloatKind:
+ case protoreflect.Sfixed32Kind, protoreflect.Fixed32Kind, protoreflect.FloatKind:
tag = append(tag, "fixed32")
- case pref.Sfixed64Kind, pref.Fixed64Kind, pref.DoubleKind:
+ case protoreflect.Sfixed64Kind, protoreflect.Fixed64Kind, protoreflect.DoubleKind:
tag = append(tag, "fixed64")
- case pref.StringKind, pref.BytesKind, pref.MessageKind:
+ case protoreflect.StringKind, protoreflect.BytesKind, protoreflect.MessageKind:
tag = append(tag, "bytes")
- case pref.GroupKind:
+ case protoreflect.GroupKind:
tag = append(tag, "group")
}
tag = append(tag, strconv.Itoa(int(fd.Number())))
switch fd.Cardinality() {
- case pref.Optional:
+ case protoreflect.Optional:
tag = append(tag, "opt")
- case pref.Required:
+ case protoreflect.Required:
tag = append(tag, "req")
- case pref.Repeated:
+ case protoreflect.Repeated:
tag = append(tag, "rep")
}
if fd.IsPacked() {
tag = append(tag, "packed")
}
name := string(fd.Name())
- if fd.Kind() == pref.GroupKind {
+ if fd.Kind() == protoreflect.GroupKind {
// The name of the FieldDescriptor for a group field is
// lowercased. To find the original capitalization, we
// look in the field's MessageType.
@@ -189,10 +189,10 @@ func Marshal(fd pref.FieldDescriptor, enumName string) string {
// The previous implementation does not tag extension fields as proto3,
// even when the field is defined in a proto3 file. Match that behavior
// for consistency.
- if fd.Syntax() == pref.Proto3 && !fd.IsExtension() {
+ if fd.Syntax() == protoreflect.Proto3 && !fd.IsExtension() {
tag = append(tag, "proto3")
}
- if fd.Kind() == pref.EnumKind && enumName != "" {
+ if fd.Kind() == protoreflect.EnumKind && enumName != "" {
tag = append(tag, "enum="+enumName)
}
if fd.ContainingOneof() != nil {
diff --git a/internal/encoding/tag/tag_test.go b/internal/encoding/tag/tag_test.go
index 9f22521d..e904a7b6 100644
--- a/internal/encoding/tag/tag_test.go
+++ b/internal/encoding/tag/tag_test.go
@@ -9,20 +9,20 @@ import (
"testing"
"google.golang.org/protobuf/internal/encoding/tag"
- fdesc "google.golang.org/protobuf/internal/filedesc"
+ "google.golang.org/protobuf/internal/filedesc"
"google.golang.org/protobuf/proto"
- pdesc "google.golang.org/protobuf/reflect/protodesc"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protodesc"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
func Test(t *testing.T) {
- fd := new(fdesc.Field)
- fd.L0.ParentFile = fdesc.SurrogateProto3
+ fd := new(filedesc.Field)
+ fd.L0.ParentFile = filedesc.SurrogateProto3
fd.L0.FullName = "foo_field"
fd.L1.Number = 1337
- fd.L1.Cardinality = pref.Repeated
- fd.L1.Kind = pref.BytesKind
- fd.L1.Default = fdesc.DefaultValue(pref.ValueOf([]byte("hello, \xde\xad\xbe\xef\n")), nil)
+ fd.L1.Cardinality = protoreflect.Repeated
+ fd.L1.Kind = protoreflect.BytesKind
+ fd.L1.Default = filedesc.DefaultValue(protoreflect.ValueOf([]byte("hello, \xde\xad\xbe\xef\n")), nil)
// Marshal test.
gotTag := tag.Marshal(fd, "")
@@ -34,7 +34,7 @@ func Test(t *testing.T) {
// Unmarshal test.
gotFD := tag.Unmarshal(wantTag, reflect.TypeOf([]byte{}), nil)
wantFD := fd
- if !proto.Equal(pdesc.ToFieldDescriptorProto(gotFD), pdesc.ToFieldDescriptorProto(wantFD)) {
+ if !proto.Equal(protodesc.ToFieldDescriptorProto(gotFD), protodesc.ToFieldDescriptorProto(wantFD)) {
t.Errorf("Umarshal() mismatch:\ngot %v\nwant %v", gotFD, wantFD)
}
}
diff --git a/internal/filedesc/desc.go b/internal/filedesc/desc.go
index 98ab142a..7c3689ba 100644
--- a/internal/filedesc/desc.go
+++ b/internal/filedesc/desc.go
@@ -17,7 +17,7 @@ import (
"google.golang.org/protobuf/internal/genid"
"google.golang.org/protobuf/internal/pragma"
"google.golang.org/protobuf/internal/strs"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
)
@@ -43,9 +43,9 @@ type (
L2 *FileL2
}
FileL1 struct {
- Syntax pref.Syntax
+ Syntax protoreflect.Syntax
Path string
- Package pref.FullName
+ Package protoreflect.FullName
Enums Enums
Messages Messages
@@ -53,36 +53,36 @@ type (
Services Services
}
FileL2 struct {
- Options func() pref.ProtoMessage
+ Options func() protoreflect.ProtoMessage
Imports FileImports
Locations SourceLocations
}
)
-func (fd *File) ParentFile() pref.FileDescriptor { return fd }
-func (fd *File) Parent() pref.Descriptor { return nil }
-func (fd *File) Index() int { return 0 }
-func (fd *File) Syntax() pref.Syntax { return fd.L1.Syntax }
-func (fd *File) Name() pref.Name { return fd.L1.Package.Name() }
-func (fd *File) FullName() pref.FullName { return fd.L1.Package }
-func (fd *File) IsPlaceholder() bool { return false }
-func (fd *File) Options() pref.ProtoMessage {
+func (fd *File) ParentFile() protoreflect.FileDescriptor { return fd }
+func (fd *File) Parent() protoreflect.Descriptor { return nil }
+func (fd *File) Index() int { return 0 }
+func (fd *File) Syntax() protoreflect.Syntax { return fd.L1.Syntax }
+func (fd *File) Name() protoreflect.Name { return fd.L1.Package.Name() }
+func (fd *File) FullName() protoreflect.FullName { return fd.L1.Package }
+func (fd *File) IsPlaceholder() bool { return false }
+func (fd *File) Options() protoreflect.ProtoMessage {
if f := fd.lazyInit().Options; f != nil {
return f()
}
return descopts.File
}
-func (fd *File) Path() string { return fd.L1.Path }
-func (fd *File) Package() pref.FullName { return fd.L1.Package }
-func (fd *File) Imports() pref.FileImports { return &fd.lazyInit().Imports }
-func (fd *File) Enums() pref.EnumDescriptors { return &fd.L1.Enums }
-func (fd *File) Messages() pref.MessageDescriptors { return &fd.L1.Messages }
-func (fd *File) Extensions() pref.ExtensionDescriptors { return &fd.L1.Extensions }
-func (fd *File) Services() pref.ServiceDescriptors { return &fd.L1.Services }
-func (fd *File) SourceLocations() pref.SourceLocations { return &fd.lazyInit().Locations }
-func (fd *File) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, fd) }
-func (fd *File) ProtoType(pref.FileDescriptor) {}
-func (fd *File) ProtoInternal(pragma.DoNotImplement) {}
+func (fd *File) Path() string { return fd.L1.Path }
+func (fd *File) Package() protoreflect.FullName { return fd.L1.Package }
+func (fd *File) Imports() protoreflect.FileImports { return &fd.lazyInit().Imports }
+func (fd *File) Enums() protoreflect.EnumDescriptors { return &fd.L1.Enums }
+func (fd *File) Messages() protoreflect.MessageDescriptors { return &fd.L1.Messages }
+func (fd *File) Extensions() protoreflect.ExtensionDescriptors { return &fd.L1.Extensions }
+func (fd *File) Services() protoreflect.ServiceDescriptors { return &fd.L1.Services }
+func (fd *File) SourceLocations() protoreflect.SourceLocations { return &fd.lazyInit().Locations }
+func (fd *File) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, fd) }
+func (fd *File) ProtoType(protoreflect.FileDescriptor) {}
+func (fd *File) ProtoInternal(pragma.DoNotImplement) {}
func (fd *File) lazyInit() *FileL2 {
if atomic.LoadUint32(&fd.once) == 0 {
@@ -119,7 +119,7 @@ type (
eagerValues bool // controls whether EnumL2.Values is already populated
}
EnumL2 struct {
- Options func() pref.ProtoMessage
+ Options func() protoreflect.ProtoMessage
Values EnumValues
ReservedNames Names
ReservedRanges EnumRanges
@@ -130,41 +130,41 @@ type (
L1 EnumValueL1
}
EnumValueL1 struct {
- Options func() pref.ProtoMessage
- Number pref.EnumNumber
+ Options func() protoreflect.ProtoMessage
+ Number protoreflect.EnumNumber
}
)
-func (ed *Enum) Options() pref.ProtoMessage {
+func (ed *Enum) Options() protoreflect.ProtoMessage {
if f := ed.lazyInit().Options; f != nil {
return f()
}
return descopts.Enum
}
-func (ed *Enum) Values() pref.EnumValueDescriptors {
+func (ed *Enum) Values() protoreflect.EnumValueDescriptors {
if ed.L1.eagerValues {
return &ed.L2.Values
}
return &ed.lazyInit().Values
}
-func (ed *Enum) ReservedNames() pref.Names { return &ed.lazyInit().ReservedNames }
-func (ed *Enum) ReservedRanges() pref.EnumRanges { return &ed.lazyInit().ReservedRanges }
-func (ed *Enum) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, ed) }
-func (ed *Enum) ProtoType(pref.EnumDescriptor) {}
+func (ed *Enum) ReservedNames() protoreflect.Names { return &ed.lazyInit().ReservedNames }
+func (ed *Enum) ReservedRanges() protoreflect.EnumRanges { return &ed.lazyInit().ReservedRanges }
+func (ed *Enum) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, ed) }
+func (ed *Enum) ProtoType(protoreflect.EnumDescriptor) {}
func (ed *Enum) lazyInit() *EnumL2 {
ed.L0.ParentFile.lazyInit() // implicitly initializes L2
return ed.L2
}
-func (ed *EnumValue) Options() pref.ProtoMessage {
+func (ed *EnumValue) Options() protoreflect.ProtoMessage {
if f := ed.L1.Options; f != nil {
return f()
}
return descopts.EnumValue
}
-func (ed *EnumValue) Number() pref.EnumNumber { return ed.L1.Number }
-func (ed *EnumValue) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, ed) }
-func (ed *EnumValue) ProtoType(pref.EnumValueDescriptor) {}
+func (ed *EnumValue) Number() protoreflect.EnumNumber { return ed.L1.Number }
+func (ed *EnumValue) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, ed) }
+func (ed *EnumValue) ProtoType(protoreflect.EnumValueDescriptor) {}
type (
Message struct {
@@ -180,14 +180,14 @@ type (
IsMessageSet bool // promoted from google.protobuf.MessageOptions
}
MessageL2 struct {
- Options func() pref.ProtoMessage
+ Options func() protoreflect.ProtoMessage
Fields Fields
Oneofs Oneofs
ReservedNames Names
ReservedRanges FieldRanges
RequiredNumbers FieldNumbers // must be consistent with Fields.Cardinality
ExtensionRanges FieldRanges
- ExtensionRangeOptions []func() pref.ProtoMessage // must be same length as ExtensionRanges
+ ExtensionRangeOptions []func() protoreflect.ProtoMessage // must be same length as ExtensionRanges
}
Field struct {
@@ -195,10 +195,10 @@ type (
L1 FieldL1
}
FieldL1 struct {
- Options func() pref.ProtoMessage
- Number pref.FieldNumber
- Cardinality pref.Cardinality // must be consistent with Message.RequiredNumbers
- Kind pref.Kind
+ Options func() protoreflect.ProtoMessage
+ Number protoreflect.FieldNumber
+ Cardinality protoreflect.Cardinality // must be consistent with Message.RequiredNumbers
+ Kind protoreflect.Kind
StringName stringName
IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto
IsWeak bool // promoted from google.protobuf.FieldOptions
@@ -207,9 +207,9 @@ type (
HasEnforceUTF8 bool // promoted from google.protobuf.FieldOptions
EnforceUTF8 bool // promoted from google.protobuf.FieldOptions
Default defaultValue
- ContainingOneof pref.OneofDescriptor // must be consistent with Message.Oneofs.Fields
- Enum pref.EnumDescriptor
- Message pref.MessageDescriptor
+ ContainingOneof protoreflect.OneofDescriptor // must be consistent with Message.Oneofs.Fields
+ Enum protoreflect.EnumDescriptor
+ Message protoreflect.MessageDescriptor
}
Oneof struct {
@@ -217,35 +217,35 @@ type (
L1 OneofL1
}
OneofL1 struct {
- Options func() pref.ProtoMessage
+ Options func() protoreflect.ProtoMessage
Fields OneofFields // must be consistent with Message.Fields.ContainingOneof
}
)
-func (md *Message) Options() pref.ProtoMessage {
+func (md *Message) Options() protoreflect.ProtoMessage {
if f := md.lazyInit().Options; f != nil {
return f()
}
return descopts.Message
}
-func (md *Message) IsMapEntry() bool { return md.L1.IsMapEntry }
-func (md *Message) Fields() pref.FieldDescriptors { return &md.lazyInit().Fields }
-func (md *Message) Oneofs() pref.OneofDescriptors { return &md.lazyInit().Oneofs }
-func (md *Message) ReservedNames() pref.Names { return &md.lazyInit().ReservedNames }
-func (md *Message) ReservedRanges() pref.FieldRanges { return &md.lazyInit().ReservedRanges }
-func (md *Message) RequiredNumbers() pref.FieldNumbers { return &md.lazyInit().RequiredNumbers }
-func (md *Message) ExtensionRanges() pref.FieldRanges { return &md.lazyInit().ExtensionRanges }
-func (md *Message) ExtensionRangeOptions(i int) pref.ProtoMessage {
+func (md *Message) IsMapEntry() bool { return md.L1.IsMapEntry }
+func (md *Message) Fields() protoreflect.FieldDescriptors { return &md.lazyInit().Fields }
+func (md *Message) Oneofs() protoreflect.OneofDescriptors { return &md.lazyInit().Oneofs }
+func (md *Message) ReservedNames() protoreflect.Names { return &md.lazyInit().ReservedNames }
+func (md *Message) ReservedRanges() protoreflect.FieldRanges { return &md.lazyInit().ReservedRanges }
+func (md *Message) RequiredNumbers() protoreflect.FieldNumbers { return &md.lazyInit().RequiredNumbers }
+func (md *Message) ExtensionRanges() protoreflect.FieldRanges { return &md.lazyInit().ExtensionRanges }
+func (md *Message) ExtensionRangeOptions(i int) protoreflect.ProtoMessage {
if f := md.lazyInit().ExtensionRangeOptions[i]; f != nil {
return f()
}
return descopts.ExtensionRange
}
-func (md *Message) Enums() pref.EnumDescriptors { return &md.L1.Enums }
-func (md *Message) Messages() pref.MessageDescriptors { return &md.L1.Messages }
-func (md *Message) Extensions() pref.ExtensionDescriptors { return &md.L1.Extensions }
-func (md *Message) ProtoType(pref.MessageDescriptor) {}
-func (md *Message) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, md) }
+func (md *Message) Enums() protoreflect.EnumDescriptors { return &md.L1.Enums }
+func (md *Message) Messages() protoreflect.MessageDescriptors { return &md.L1.Messages }
+func (md *Message) Extensions() protoreflect.ExtensionDescriptors { return &md.L1.Extensions }
+func (md *Message) ProtoType(protoreflect.MessageDescriptor) {}
+func (md *Message) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, md) }
func (md *Message) lazyInit() *MessageL2 {
md.L0.ParentFile.lazyInit() // implicitly initializes L2
return md.L2
@@ -260,28 +260,28 @@ func (md *Message) IsMessageSet() bool {
return md.L1.IsMessageSet
}
-func (fd *Field) Options() pref.ProtoMessage {
+func (fd *Field) Options() protoreflect.ProtoMessage {
if f := fd.L1.Options; f != nil {
return f()
}
return descopts.Field
}
-func (fd *Field) Number() pref.FieldNumber { return fd.L1.Number }
-func (fd *Field) Cardinality() pref.Cardinality { return fd.L1.Cardinality }
-func (fd *Field) Kind() pref.Kind { return fd.L1.Kind }
-func (fd *Field) HasJSONName() bool { return fd.L1.StringName.hasJSON }
-func (fd *Field) JSONName() string { return fd.L1.StringName.getJSON(fd) }
-func (fd *Field) TextName() string { return fd.L1.StringName.getText(fd) }
+func (fd *Field) Number() protoreflect.FieldNumber { return fd.L1.Number }
+func (fd *Field) Cardinality() protoreflect.Cardinality { return fd.L1.Cardinality }
+func (fd *Field) Kind() protoreflect.Kind { return fd.L1.Kind }
+func (fd *Field) HasJSONName() bool { return fd.L1.StringName.hasJSON }
+func (fd *Field) JSONName() string { return fd.L1.StringName.getJSON(fd) }
+func (fd *Field) TextName() string { return fd.L1.StringName.getText(fd) }
func (fd *Field) HasPresence() bool {
- return fd.L1.Cardinality != pref.Repeated && (fd.L0.ParentFile.L1.Syntax == pref.Proto2 || fd.L1.Message != nil || fd.L1.ContainingOneof != nil)
+ return fd.L1.Cardinality != protoreflect.Repeated && (fd.L0.ParentFile.L1.Syntax == protoreflect.Proto2 || fd.L1.Message != nil || fd.L1.ContainingOneof != nil)
}
func (fd *Field) HasOptionalKeyword() bool {
- return (fd.L0.ParentFile.L1.Syntax == pref.Proto2 && fd.L1.Cardinality == pref.Optional && fd.L1.ContainingOneof == nil) || fd.L1.IsProto3Optional
+ return (fd.L0.ParentFile.L1.Syntax == protoreflect.Proto2 && fd.L1.Cardinality == protoreflect.Optional && fd.L1.ContainingOneof == nil) || fd.L1.IsProto3Optional
}
func (fd *Field) IsPacked() bool {
- if !fd.L1.HasPacked && fd.L0.ParentFile.L1.Syntax != pref.Proto2 && fd.L1.Cardinality == pref.Repeated {
+ if !fd.L1.HasPacked && fd.L0.ParentFile.L1.Syntax != protoreflect.Proto2 && fd.L1.Cardinality == protoreflect.Repeated {
switch fd.L1.Kind {
- case pref.StringKind, pref.BytesKind, pref.MessageKind, pref.GroupKind:
+ case protoreflect.StringKind, protoreflect.BytesKind, protoreflect.MessageKind, protoreflect.GroupKind:
default:
return true
}
@@ -290,40 +290,40 @@ func (fd *Field) IsPacked() bool {
}
func (fd *Field) IsExtension() bool { return false }
func (fd *Field) IsWeak() bool { return fd.L1.IsWeak }
-func (fd *Field) IsList() bool { return fd.Cardinality() == pref.Repeated && !fd.IsMap() }
+func (fd *Field) IsList() bool { return fd.Cardinality() == protoreflect.Repeated && !fd.IsMap() }
func (fd *Field) IsMap() bool { return fd.Message() != nil && fd.Message().IsMapEntry() }
-func (fd *Field) MapKey() pref.FieldDescriptor {
+func (fd *Field) MapKey() protoreflect.FieldDescriptor {
if !fd.IsMap() {
return nil
}
return fd.Message().Fields().ByNumber(genid.MapEntry_Key_field_number)
}
-func (fd *Field) MapValue() pref.FieldDescriptor {
+func (fd *Field) MapValue() protoreflect.FieldDescriptor {
if !fd.IsMap() {
return nil
}
return fd.Message().Fields().ByNumber(genid.MapEntry_Value_field_number)
}
-func (fd *Field) HasDefault() bool { return fd.L1.Default.has }
-func (fd *Field) Default() pref.Value { return fd.L1.Default.get(fd) }
-func (fd *Field) DefaultEnumValue() pref.EnumValueDescriptor { return fd.L1.Default.enum }
-func (fd *Field) ContainingOneof() pref.OneofDescriptor { return fd.L1.ContainingOneof }
-func (fd *Field) ContainingMessage() pref.MessageDescriptor {
- return fd.L0.Parent.(pref.MessageDescriptor)
+func (fd *Field) HasDefault() bool { return fd.L1.Default.has }
+func (fd *Field) Default() protoreflect.Value { return fd.L1.Default.get(fd) }
+func (fd *Field) DefaultEnumValue() protoreflect.EnumValueDescriptor { return fd.L1.Default.enum }
+func (fd *Field) ContainingOneof() protoreflect.OneofDescriptor { return fd.L1.ContainingOneof }
+func (fd *Field) ContainingMessage() protoreflect.MessageDescriptor {
+ return fd.L0.Parent.(protoreflect.MessageDescriptor)
}
-func (fd *Field) Enum() pref.EnumDescriptor {
+func (fd *Field) Enum() protoreflect.EnumDescriptor {
return fd.L1.Enum
}
-func (fd *Field) Message() pref.MessageDescriptor {
+func (fd *Field) Message() protoreflect.MessageDescriptor {
if fd.L1.IsWeak {
if d, _ := protoregistry.GlobalFiles.FindDescriptorByName(fd.L1.Message.FullName()); d != nil {
- return d.(pref.MessageDescriptor)
+ return d.(protoreflect.MessageDescriptor)
}
}
return fd.L1.Message
}
-func (fd *Field) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, fd) }
-func (fd *Field) ProtoType(pref.FieldDescriptor) {}
+func (fd *Field) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, fd) }
+func (fd *Field) ProtoType(protoreflect.FieldDescriptor) {}
// EnforceUTF8 is a pseudo-internal API to determine whether to enforce UTF-8
// validation for the string field. This exists for Google-internal use only
@@ -336,21 +336,21 @@ func (fd *Field) EnforceUTF8() bool {
if fd.L1.HasEnforceUTF8 {
return fd.L1.EnforceUTF8
}
- return fd.L0.ParentFile.L1.Syntax == pref.Proto3
+ return fd.L0.ParentFile.L1.Syntax == protoreflect.Proto3
}
func (od *Oneof) IsSynthetic() bool {
- return od.L0.ParentFile.L1.Syntax == pref.Proto3 && len(od.L1.Fields.List) == 1 && od.L1.Fields.List[0].HasOptionalKeyword()
+ return od.L0.ParentFile.L1.Syntax == protoreflect.Proto3 && len(od.L1.Fields.List) == 1 && od.L1.Fields.List[0].HasOptionalKeyword()
}
-func (od *Oneof) Options() pref.ProtoMessage {
+func (od *Oneof) Options() protoreflect.ProtoMessage {
if f := od.L1.Options; f != nil {
return f()
}
return descopts.Oneof
}
-func (od *Oneof) Fields() pref.FieldDescriptors { return &od.L1.Fields }
-func (od *Oneof) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, od) }
-func (od *Oneof) ProtoType(pref.OneofDescriptor) {}
+func (od *Oneof) Fields() protoreflect.FieldDescriptors { return &od.L1.Fields }
+func (od *Oneof) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, od) }
+func (od *Oneof) ProtoType(protoreflect.OneofDescriptor) {}
type (
Extension struct {
@@ -359,55 +359,57 @@ type (
L2 *ExtensionL2 // protected by fileDesc.once
}
ExtensionL1 struct {
- Number pref.FieldNumber
- Extendee pref.MessageDescriptor
- Cardinality pref.Cardinality
- Kind pref.Kind
+ Number protoreflect.FieldNumber
+ Extendee protoreflect.MessageDescriptor
+ Cardinality protoreflect.Cardinality
+ Kind protoreflect.Kind
}
ExtensionL2 struct {
- Options func() pref.ProtoMessage
+ Options func() protoreflect.ProtoMessage
StringName stringName
IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto
IsPacked bool // promoted from google.protobuf.FieldOptions
Default defaultValue
- Enum pref.EnumDescriptor
- Message pref.MessageDescriptor
+ Enum protoreflect.EnumDescriptor
+ Message protoreflect.MessageDescriptor
}
)
-func (xd *Extension) Options() pref.ProtoMessage {
+func (xd *Extension) Options() protoreflect.ProtoMessage {
if f := xd.lazyInit().Options; f != nil {
return f()
}
return descopts.Field
}
-func (xd *Extension) Number() pref.FieldNumber { return xd.L1.Number }
-func (xd *Extension) Cardinality() pref.Cardinality { return xd.L1.Cardinality }
-func (xd *Extension) Kind() pref.Kind { return xd.L1.Kind }
-func (xd *Extension) HasJSONName() bool { return xd.lazyInit().StringName.hasJSON }
-func (xd *Extension) JSONName() string { return xd.lazyInit().StringName.getJSON(xd) }
-func (xd *Extension) TextName() string { return xd.lazyInit().StringName.getText(xd) }
-func (xd *Extension) HasPresence() bool { return xd.L1.Cardinality != pref.Repeated }
+func (xd *Extension) Number() protoreflect.FieldNumber { return xd.L1.Number }
+func (xd *Extension) Cardinality() protoreflect.Cardinality { return xd.L1.Cardinality }
+func (xd *Extension) Kind() protoreflect.Kind { return xd.L1.Kind }
+func (xd *Extension) HasJSONName() bool { return xd.lazyInit().StringName.hasJSON }
+func (xd *Extension) JSONName() string { return xd.lazyInit().StringName.getJSON(xd) }
+func (xd *Extension) TextName() string { return xd.lazyInit().StringName.getText(xd) }
+func (xd *Extension) HasPresence() bool { return xd.L1.Cardinality != protoreflect.Repeated }
func (xd *Extension) HasOptionalKeyword() bool {
- return (xd.L0.ParentFile.L1.Syntax == pref.Proto2 && xd.L1.Cardinality == pref.Optional) || xd.lazyInit().IsProto3Optional
-}
-func (xd *Extension) IsPacked() bool { return xd.lazyInit().IsPacked }
-func (xd *Extension) IsExtension() bool { return true }
-func (xd *Extension) IsWeak() bool { return false }
-func (xd *Extension) IsList() bool { return xd.Cardinality() == pref.Repeated }
-func (xd *Extension) IsMap() bool { return false }
-func (xd *Extension) MapKey() pref.FieldDescriptor { return nil }
-func (xd *Extension) MapValue() pref.FieldDescriptor { return nil }
-func (xd *Extension) HasDefault() bool { return xd.lazyInit().Default.has }
-func (xd *Extension) Default() pref.Value { return xd.lazyInit().Default.get(xd) }
-func (xd *Extension) DefaultEnumValue() pref.EnumValueDescriptor { return xd.lazyInit().Default.enum }
-func (xd *Extension) ContainingOneof() pref.OneofDescriptor { return nil }
-func (xd *Extension) ContainingMessage() pref.MessageDescriptor { return xd.L1.Extendee }
-func (xd *Extension) Enum() pref.EnumDescriptor { return xd.lazyInit().Enum }
-func (xd *Extension) Message() pref.MessageDescriptor { return xd.lazyInit().Message }
-func (xd *Extension) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, xd) }
-func (xd *Extension) ProtoType(pref.FieldDescriptor) {}
-func (xd *Extension) ProtoInternal(pragma.DoNotImplement) {}
+ return (xd.L0.ParentFile.L1.Syntax == protoreflect.Proto2 && xd.L1.Cardinality == protoreflect.Optional) || xd.lazyInit().IsProto3Optional
+}
+func (xd *Extension) IsPacked() bool { return xd.lazyInit().IsPacked }
+func (xd *Extension) IsExtension() bool { return true }
+func (xd *Extension) IsWeak() bool { return false }
+func (xd *Extension) IsList() bool { return xd.Cardinality() == protoreflect.Repeated }
+func (xd *Extension) IsMap() bool { return false }
+func (xd *Extension) MapKey() protoreflect.FieldDescriptor { return nil }
+func (xd *Extension) MapValue() protoreflect.FieldDescriptor { return nil }
+func (xd *Extension) HasDefault() bool { return xd.lazyInit().Default.has }
+func (xd *Extension) Default() protoreflect.Value { return xd.lazyInit().Default.get(xd) }
+func (xd *Extension) DefaultEnumValue() protoreflect.EnumValueDescriptor {
+ return xd.lazyInit().Default.enum
+}
+func (xd *Extension) ContainingOneof() protoreflect.OneofDescriptor { return nil }
+func (xd *Extension) ContainingMessage() protoreflect.MessageDescriptor { return xd.L1.Extendee }
+func (xd *Extension) Enum() protoreflect.EnumDescriptor { return xd.lazyInit().Enum }
+func (xd *Extension) Message() protoreflect.MessageDescriptor { return xd.lazyInit().Message }
+func (xd *Extension) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, xd) }
+func (xd *Extension) ProtoType(protoreflect.FieldDescriptor) {}
+func (xd *Extension) ProtoInternal(pragma.DoNotImplement) {}
func (xd *Extension) lazyInit() *ExtensionL2 {
xd.L0.ParentFile.lazyInit() // implicitly initializes L2
return xd.L2
@@ -421,7 +423,7 @@ type (
}
ServiceL1 struct{}
ServiceL2 struct {
- Options func() pref.ProtoMessage
+ Options func() protoreflect.ProtoMessage
Methods Methods
}
@@ -430,48 +432,48 @@ type (
L1 MethodL1
}
MethodL1 struct {
- Options func() pref.ProtoMessage
- Input pref.MessageDescriptor
- Output pref.MessageDescriptor
+ Options func() protoreflect.ProtoMessage
+ Input protoreflect.MessageDescriptor
+ Output protoreflect.MessageDescriptor
IsStreamingClient bool
IsStreamingServer bool
}
)
-func (sd *Service) Options() pref.ProtoMessage {
+func (sd *Service) Options() protoreflect.ProtoMessage {
if f := sd.lazyInit().Options; f != nil {
return f()
}
return descopts.Service
}
-func (sd *Service) Methods() pref.MethodDescriptors { return &sd.lazyInit().Methods }
-func (sd *Service) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, sd) }
-func (sd *Service) ProtoType(pref.ServiceDescriptor) {}
-func (sd *Service) ProtoInternal(pragma.DoNotImplement) {}
+func (sd *Service) Methods() protoreflect.MethodDescriptors { return &sd.lazyInit().Methods }
+func (sd *Service) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, sd) }
+func (sd *Service) ProtoType(protoreflect.ServiceDescriptor) {}
+func (sd *Service) ProtoInternal(pragma.DoNotImplement) {}
func (sd *Service) lazyInit() *ServiceL2 {
sd.L0.ParentFile.lazyInit() // implicitly initializes L2
return sd.L2
}
-func (md *Method) Options() pref.ProtoMessage {
+func (md *Method) Options() protoreflect.ProtoMessage {
if f := md.L1.Options; f != nil {
return f()
}
return descopts.Method
}
-func (md *Method) Input() pref.MessageDescriptor { return md.L1.Input }
-func (md *Method) Output() pref.MessageDescriptor { return md.L1.Output }
-func (md *Method) IsStreamingClient() bool { return md.L1.IsStreamingClient }
-func (md *Method) IsStreamingServer() bool { return md.L1.IsStreamingServer }
-func (md *Method) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, md) }
-func (md *Method) ProtoType(pref.MethodDescriptor) {}
-func (md *Method) ProtoInternal(pragma.DoNotImplement) {}
+func (md *Method) Input() protoreflect.MessageDescriptor { return md.L1.Input }
+func (md *Method) Output() protoreflect.MessageDescriptor { return md.L1.Output }
+func (md *Method) IsStreamingClient() bool { return md.L1.IsStreamingClient }
+func (md *Method) IsStreamingServer() bool { return md.L1.IsStreamingServer }
+func (md *Method) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, md) }
+func (md *Method) ProtoType(protoreflect.MethodDescriptor) {}
+func (md *Method) ProtoInternal(pragma.DoNotImplement) {}
// Surrogate files are can be used to create standalone descriptors
// where the syntax is only information derived from the parent file.
var (
- SurrogateProto2 = &File{L1: FileL1{Syntax: pref.Proto2}, L2: &FileL2{}}
- SurrogateProto3 = &File{L1: FileL1{Syntax: pref.Proto3}, L2: &FileL2{}}
+ SurrogateProto2 = &File{L1: FileL1{Syntax: protoreflect.Proto2}, L2: &FileL2{}}
+ SurrogateProto3 = &File{L1: FileL1{Syntax: protoreflect.Proto3}, L2: &FileL2{}}
)
type (
@@ -479,24 +481,24 @@ type (
L0 BaseL0
}
BaseL0 struct {
- FullName pref.FullName // must be populated
- ParentFile *File // must be populated
- Parent pref.Descriptor
+ FullName protoreflect.FullName // must be populated
+ ParentFile *File // must be populated
+ Parent protoreflect.Descriptor
Index int
}
)
-func (d *Base) Name() pref.Name { return d.L0.FullName.Name() }
-func (d *Base) FullName() pref.FullName { return d.L0.FullName }
-func (d *Base) ParentFile() pref.FileDescriptor {
+func (d *Base) Name() protoreflect.Name { return d.L0.FullName.Name() }
+func (d *Base) FullName() protoreflect.FullName { return d.L0.FullName }
+func (d *Base) ParentFile() protoreflect.FileDescriptor {
if d.L0.ParentFile == SurrogateProto2 || d.L0.ParentFile == SurrogateProto3 {
return nil // surrogate files are not real parents
}
return d.L0.ParentFile
}
-func (d *Base) Parent() pref.Descriptor { return d.L0.Parent }
+func (d *Base) Parent() protoreflect.Descriptor { return d.L0.Parent }
func (d *Base) Index() int { return d.L0.Index }
-func (d *Base) Syntax() pref.Syntax { return d.L0.ParentFile.Syntax() }
+func (d *Base) Syntax() protoreflect.Syntax { return d.L0.ParentFile.Syntax() }
func (d *Base) IsPlaceholder() bool { return false }
func (d *Base) ProtoInternal(pragma.DoNotImplement) {}
@@ -513,7 +515,7 @@ func (s *stringName) InitJSON(name string) {
s.nameJSON = name
}
-func (s *stringName) lazyInit(fd pref.FieldDescriptor) *stringName {
+func (s *stringName) lazyInit(fd protoreflect.FieldDescriptor) *stringName {
s.once.Do(func() {
if fd.IsExtension() {
// For extensions, JSON and text are formatted the same way.
@@ -533,7 +535,7 @@ func (s *stringName) lazyInit(fd pref.FieldDescriptor) *stringName {
// Format the text name.
s.nameText = string(fd.Name())
- if fd.Kind() == pref.GroupKind {
+ if fd.Kind() == protoreflect.GroupKind {
s.nameText = string(fd.Message().Name())
}
}
@@ -541,10 +543,10 @@ func (s *stringName) lazyInit(fd pref.FieldDescriptor) *stringName {
return s
}
-func (s *stringName) getJSON(fd pref.FieldDescriptor) string { return s.lazyInit(fd).nameJSON }
-func (s *stringName) getText(fd pref.FieldDescriptor) string { return s.lazyInit(fd).nameText }
+func (s *stringName) getJSON(fd protoreflect.FieldDescriptor) string { return s.lazyInit(fd).nameJSON }
+func (s *stringName) getText(fd protoreflect.FieldDescriptor) string { return s.lazyInit(fd).nameText }
-func DefaultValue(v pref.Value, ev pref.EnumValueDescriptor) defaultValue {
+func DefaultValue(v protoreflect.Value, ev protoreflect.EnumValueDescriptor) defaultValue {
dv := defaultValue{has: v.IsValid(), val: v, enum: ev}
if b, ok := v.Interface().([]byte); ok {
// Store a copy of the default bytes, so that we can detect
@@ -554,9 +556,9 @@ func DefaultValue(v pref.Value, ev pref.EnumValueDescriptor) defaultValue {
return dv
}
-func unmarshalDefault(b []byte, k pref.Kind, pf *File, ed pref.EnumDescriptor) defaultValue {
- var evs pref.EnumValueDescriptors
- if k == pref.EnumKind {
+func unmarshalDefault(b []byte, k protoreflect.Kind, pf *File, ed protoreflect.EnumDescriptor) defaultValue {
+ var evs protoreflect.EnumValueDescriptors
+ if k == protoreflect.EnumKind {
// If the enum is declared within the same file, be careful not to
// blindly call the Values method, lest we bind ourselves in a deadlock.
if e, ok := ed.(*Enum); ok && e.L0.ParentFile == pf {
@@ -567,9 +569,9 @@ func unmarshalDefault(b []byte, k pref.Kind, pf *File, ed pref.EnumDescriptor) d
// If we are unable to resolve the enum dependency, use a placeholder
// enum value since we will not be able to parse the default value.
- if ed.IsPlaceholder() && pref.Name(b).IsValid() {
- v := pref.ValueOfEnum(0)
- ev := PlaceholderEnumValue(ed.FullName().Parent().Append(pref.Name(b)))
+ if ed.IsPlaceholder() && protoreflect.Name(b).IsValid() {
+ v := protoreflect.ValueOfEnum(0)
+ ev := PlaceholderEnumValue(ed.FullName().Parent().Append(protoreflect.Name(b)))
return DefaultValue(v, ev)
}
}
@@ -583,41 +585,41 @@ func unmarshalDefault(b []byte, k pref.Kind, pf *File, ed pref.EnumDescriptor) d
type defaultValue struct {
has bool
- val pref.Value
- enum pref.EnumValueDescriptor
+ val protoreflect.Value
+ enum protoreflect.EnumValueDescriptor
bytes []byte
}
-func (dv *defaultValue) get(fd pref.FieldDescriptor) pref.Value {
+func (dv *defaultValue) get(fd protoreflect.FieldDescriptor) protoreflect.Value {
// Return the zero value as the default if unpopulated.
if !dv.has {
- if fd.Cardinality() == pref.Repeated {
- return pref.Value{}
+ if fd.Cardinality() == protoreflect.Repeated {
+ return protoreflect.Value{}
}
switch fd.Kind() {
- case pref.BoolKind:
- return pref.ValueOfBool(false)
- case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
- return pref.ValueOfInt32(0)
- case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
- return pref.ValueOfInt64(0)
- case pref.Uint32Kind, pref.Fixed32Kind:
- return pref.ValueOfUint32(0)
- case pref.Uint64Kind, pref.Fixed64Kind:
- return pref.ValueOfUint64(0)
- case pref.FloatKind:
- return pref.ValueOfFloat32(0)
- case pref.DoubleKind:
- return pref.ValueOfFloat64(0)
- case pref.StringKind:
- return pref.ValueOfString("")
- case pref.BytesKind:
- return pref.ValueOfBytes(nil)
- case pref.EnumKind:
+ case protoreflect.BoolKind:
+ return protoreflect.ValueOfBool(false)
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
+ return protoreflect.ValueOfInt32(0)
+ case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
+ return protoreflect.ValueOfInt64(0)
+ case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
+ return protoreflect.ValueOfUint32(0)
+ case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
+ return protoreflect.ValueOfUint64(0)
+ case protoreflect.FloatKind:
+ return protoreflect.ValueOfFloat32(0)
+ case protoreflect.DoubleKind:
+ return protoreflect.ValueOfFloat64(0)
+ case protoreflect.StringKind:
+ return protoreflect.ValueOfString("")
+ case protoreflect.BytesKind:
+ return protoreflect.ValueOfBytes(nil)
+ case protoreflect.EnumKind:
if evs := fd.Enum().Values(); evs.Len() > 0 {
- return pref.ValueOfEnum(evs.Get(0).Number())
+ return protoreflect.ValueOfEnum(evs.Get(0).Number())
}
- return pref.ValueOfEnum(0)
+ return protoreflect.ValueOfEnum(0)
}
}
diff --git a/internal/filedesc/desc_init.go b/internal/filedesc/desc_init.go
index 66e1fee5..4a1584c9 100644
--- a/internal/filedesc/desc_init.go
+++ b/internal/filedesc/desc_init.go
@@ -10,7 +10,7 @@ import (
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/genid"
"google.golang.org/protobuf/internal/strs"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
// fileRaw is a data struct used when initializing a file descriptor from
@@ -95,7 +95,7 @@ func (fd *File) unmarshalSeed(b []byte) {
sb := getBuilder()
defer putBuilder(sb)
- var prevField pref.FieldNumber
+ var prevField protoreflect.FieldNumber
var numEnums, numMessages, numExtensions, numServices int
var posEnums, posMessages, posExtensions, posServices int
b0 := b
@@ -110,16 +110,16 @@ func (fd *File) unmarshalSeed(b []byte) {
case genid.FileDescriptorProto_Syntax_field_number:
switch string(v) {
case "proto2":
- fd.L1.Syntax = pref.Proto2
+ fd.L1.Syntax = protoreflect.Proto2
case "proto3":
- fd.L1.Syntax = pref.Proto3
+ fd.L1.Syntax = protoreflect.Proto3
default:
panic("invalid syntax")
}
case genid.FileDescriptorProto_Name_field_number:
fd.L1.Path = sb.MakeString(v)
case genid.FileDescriptorProto_Package_field_number:
- fd.L1.Package = pref.FullName(sb.MakeString(v))
+ fd.L1.Package = protoreflect.FullName(sb.MakeString(v))
case genid.FileDescriptorProto_EnumType_field_number:
if prevField != genid.FileDescriptorProto_EnumType_field_number {
if numEnums > 0 {
@@ -163,7 +163,7 @@ func (fd *File) unmarshalSeed(b []byte) {
// If syntax is missing, it is assumed to be proto2.
if fd.L1.Syntax == 0 {
- fd.L1.Syntax = pref.Proto2
+ fd.L1.Syntax = protoreflect.Proto2
}
// Must allocate all declarations before parsing each descriptor type
@@ -219,7 +219,7 @@ func (fd *File) unmarshalSeed(b []byte) {
}
}
-func (ed *Enum) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
+func (ed *Enum) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
ed.L0.ParentFile = pf
ed.L0.Parent = pd
ed.L0.Index = i
@@ -271,12 +271,12 @@ func (ed *Enum) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd pref.Desc
}
}
-func (md *Message) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
+func (md *Message) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
md.L0.ParentFile = pf
md.L0.Parent = pd
md.L0.Index = i
- var prevField pref.FieldNumber
+ var prevField protoreflect.FieldNumber
var numEnums, numMessages, numExtensions int
var posEnums, posMessages, posExtensions int
b0 := b
@@ -387,7 +387,7 @@ func (md *Message) unmarshalSeedOptions(b []byte) {
}
}
-func (xd *Extension) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
+func (xd *Extension) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
xd.L0.ParentFile = pf
xd.L0.Parent = pd
xd.L0.Index = i
@@ -401,11 +401,11 @@ func (xd *Extension) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd pref
b = b[m:]
switch num {
case genid.FieldDescriptorProto_Number_field_number:
- xd.L1.Number = pref.FieldNumber(v)
+ xd.L1.Number = protoreflect.FieldNumber(v)
case genid.FieldDescriptorProto_Label_field_number:
- xd.L1.Cardinality = pref.Cardinality(v)
+ xd.L1.Cardinality = protoreflect.Cardinality(v)
case genid.FieldDescriptorProto_Type_field_number:
- xd.L1.Kind = pref.Kind(v)
+ xd.L1.Kind = protoreflect.Kind(v)
}
case protowire.BytesType:
v, m := protowire.ConsumeBytes(b)
@@ -423,7 +423,7 @@ func (xd *Extension) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd pref
}
}
-func (sd *Service) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
+func (sd *Service) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
sd.L0.ParentFile = pf
sd.L0.Parent = pd
sd.L0.Index = i
@@ -459,13 +459,13 @@ func putBuilder(b *strs.Builder) {
// makeFullName converts b to a protoreflect.FullName,
// where b must start with a leading dot.
-func makeFullName(sb *strs.Builder, b []byte) pref.FullName {
+func makeFullName(sb *strs.Builder, b []byte) protoreflect.FullName {
if len(b) == 0 || b[0] != '.' {
panic("name reference must be fully qualified")
}
- return pref.FullName(sb.MakeString(b[1:]))
+ return protoreflect.FullName(sb.MakeString(b[1:]))
}
-func appendFullName(sb *strs.Builder, prefix pref.FullName, suffix []byte) pref.FullName {
- return sb.AppendFullName(prefix, pref.Name(strs.UnsafeString(suffix)))
+func appendFullName(sb *strs.Builder, prefix protoreflect.FullName, suffix []byte) protoreflect.FullName {
+ return sb.AppendFullName(prefix, protoreflect.Name(strs.UnsafeString(suffix)))
}
diff --git a/internal/filedesc/desc_lazy.go b/internal/filedesc/desc_lazy.go
index 198451e3..736a19a7 100644
--- a/internal/filedesc/desc_lazy.go
+++ b/internal/filedesc/desc_lazy.go
@@ -13,7 +13,7 @@ import (
"google.golang.org/protobuf/internal/genid"
"google.golang.org/protobuf/internal/strs"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
func (fd *File) lazyRawInit() {
@@ -39,10 +39,10 @@ func (file *File) resolveMessages() {
// Resolve message field dependency.
switch fd.L1.Kind {
- case pref.EnumKind:
+ case protoreflect.EnumKind:
fd.L1.Enum = file.resolveEnumDependency(fd.L1.Enum, listFieldDeps, depIdx)
depIdx++
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
fd.L1.Message = file.resolveMessageDependency(fd.L1.Message, listFieldDeps, depIdx)
depIdx++
}
@@ -62,10 +62,10 @@ func (file *File) resolveExtensions() {
// Resolve extension field dependency.
switch xd.L1.Kind {
- case pref.EnumKind:
+ case protoreflect.EnumKind:
xd.L2.Enum = file.resolveEnumDependency(xd.L2.Enum, listExtDeps, depIdx)
depIdx++
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
xd.L2.Message = file.resolveMessageDependency(xd.L2.Message, listExtDeps, depIdx)
depIdx++
}
@@ -92,7 +92,7 @@ func (file *File) resolveServices() {
}
}
-func (file *File) resolveEnumDependency(ed pref.EnumDescriptor, i, j int32) pref.EnumDescriptor {
+func (file *File) resolveEnumDependency(ed protoreflect.EnumDescriptor, i, j int32) protoreflect.EnumDescriptor {
r := file.builder.FileRegistry
if r, ok := r.(resolverByIndex); ok {
if ed2 := r.FindEnumByIndex(i, j, file.allEnums, file.allMessages); ed2 != nil {
@@ -105,12 +105,12 @@ func (file *File) resolveEnumDependency(ed pref.EnumDescriptor, i, j int32) pref
}
}
if d, _ := r.FindDescriptorByName(ed.FullName()); d != nil {
- return d.(pref.EnumDescriptor)
+ return d.(protoreflect.EnumDescriptor)
}
return ed
}
-func (file *File) resolveMessageDependency(md pref.MessageDescriptor, i, j int32) pref.MessageDescriptor {
+func (file *File) resolveMessageDependency(md protoreflect.MessageDescriptor, i, j int32) protoreflect.MessageDescriptor {
r := file.builder.FileRegistry
if r, ok := r.(resolverByIndex); ok {
if md2 := r.FindMessageByIndex(i, j, file.allEnums, file.allMessages); md2 != nil {
@@ -123,7 +123,7 @@ func (file *File) resolveMessageDependency(md pref.MessageDescriptor, i, j int32
}
}
if d, _ := r.FindDescriptorByName(md.FullName()); d != nil {
- return d.(pref.MessageDescriptor)
+ return d.(protoreflect.MessageDescriptor)
}
return md
}
@@ -158,7 +158,7 @@ func (fd *File) unmarshalFull(b []byte) {
if imp == nil {
imp = PlaceholderFile(path)
}
- fd.L2.Imports = append(fd.L2.Imports, pref.FileImport{FileDescriptor: imp})
+ fd.L2.Imports = append(fd.L2.Imports, protoreflect.FileImport{FileDescriptor: imp})
case genid.FileDescriptorProto_EnumType_field_number:
fd.L1.Enums.List[enumIdx].unmarshalFull(v, sb)
enumIdx++
@@ -199,7 +199,7 @@ func (ed *Enum) unmarshalFull(b []byte, sb *strs.Builder) {
case genid.EnumDescriptorProto_Value_field_number:
rawValues = append(rawValues, v)
case genid.EnumDescriptorProto_ReservedName_field_number:
- ed.L2.ReservedNames.List = append(ed.L2.ReservedNames.List, pref.Name(sb.MakeString(v)))
+ ed.L2.ReservedNames.List = append(ed.L2.ReservedNames.List, protoreflect.Name(sb.MakeString(v)))
case genid.EnumDescriptorProto_ReservedRange_field_number:
ed.L2.ReservedRanges.List = append(ed.L2.ReservedRanges.List, unmarshalEnumReservedRange(v))
case genid.EnumDescriptorProto_Options_field_number:
@@ -219,7 +219,7 @@ func (ed *Enum) unmarshalFull(b []byte, sb *strs.Builder) {
ed.L2.Options = ed.L0.ParentFile.builder.optionsUnmarshaler(&descopts.Enum, rawOptions)
}
-func unmarshalEnumReservedRange(b []byte) (r [2]pref.EnumNumber) {
+func unmarshalEnumReservedRange(b []byte) (r [2]protoreflect.EnumNumber) {
for len(b) > 0 {
num, typ, n := protowire.ConsumeTag(b)
b = b[n:]
@@ -229,9 +229,9 @@ func unmarshalEnumReservedRange(b []byte) (r [2]pref.EnumNumber) {
b = b[m:]
switch num {
case genid.EnumDescriptorProto_EnumReservedRange_Start_field_number:
- r[0] = pref.EnumNumber(v)
+ r[0] = protoreflect.EnumNumber(v)
case genid.EnumDescriptorProto_EnumReservedRange_End_field_number:
- r[1] = pref.EnumNumber(v)
+ r[1] = protoreflect.EnumNumber(v)
}
default:
m := protowire.ConsumeFieldValue(num, typ, b)
@@ -241,7 +241,7 @@ func unmarshalEnumReservedRange(b []byte) (r [2]pref.EnumNumber) {
return r
}
-func (vd *EnumValue) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
+func (vd *EnumValue) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
vd.L0.ParentFile = pf
vd.L0.Parent = pd
vd.L0.Index = i
@@ -256,7 +256,7 @@ func (vd *EnumValue) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd pref
b = b[m:]
switch num {
case genid.EnumValueDescriptorProto_Number_field_number:
- vd.L1.Number = pref.EnumNumber(v)
+ vd.L1.Number = protoreflect.EnumNumber(v)
}
case protowire.BytesType:
v, m := protowire.ConsumeBytes(b)
@@ -294,7 +294,7 @@ func (md *Message) unmarshalFull(b []byte, sb *strs.Builder) {
case genid.DescriptorProto_OneofDecl_field_number:
rawOneofs = append(rawOneofs, v)
case genid.DescriptorProto_ReservedName_field_number:
- md.L2.ReservedNames.List = append(md.L2.ReservedNames.List, pref.Name(sb.MakeString(v)))
+ md.L2.ReservedNames.List = append(md.L2.ReservedNames.List, protoreflect.Name(sb.MakeString(v)))
case genid.DescriptorProto_ReservedRange_field_number:
md.L2.ReservedRanges.List = append(md.L2.ReservedRanges.List, unmarshalMessageReservedRange(v))
case genid.DescriptorProto_ExtensionRange_field_number:
@@ -326,7 +326,7 @@ func (md *Message) unmarshalFull(b []byte, sb *strs.Builder) {
for i, b := range rawFields {
fd := &md.L2.Fields.List[i]
fd.unmarshalFull(b, sb, md.L0.ParentFile, md, i)
- if fd.L1.Cardinality == pref.Required {
+ if fd.L1.Cardinality == protoreflect.Required {
md.L2.RequiredNumbers.List = append(md.L2.RequiredNumbers.List, fd.L1.Number)
}
}
@@ -359,7 +359,7 @@ func (md *Message) unmarshalOptions(b []byte) {
}
}
-func unmarshalMessageReservedRange(b []byte) (r [2]pref.FieldNumber) {
+func unmarshalMessageReservedRange(b []byte) (r [2]protoreflect.FieldNumber) {
for len(b) > 0 {
num, typ, n := protowire.ConsumeTag(b)
b = b[n:]
@@ -369,9 +369,9 @@ func unmarshalMessageReservedRange(b []byte) (r [2]pref.FieldNumber) {
b = b[m:]
switch num {
case genid.DescriptorProto_ReservedRange_Start_field_number:
- r[0] = pref.FieldNumber(v)
+ r[0] = protoreflect.FieldNumber(v)
case genid.DescriptorProto_ReservedRange_End_field_number:
- r[1] = pref.FieldNumber(v)
+ r[1] = protoreflect.FieldNumber(v)
}
default:
m := protowire.ConsumeFieldValue(num, typ, b)
@@ -381,7 +381,7 @@ func unmarshalMessageReservedRange(b []byte) (r [2]pref.FieldNumber) {
return r
}
-func unmarshalMessageExtensionRange(b []byte) (r [2]pref.FieldNumber, rawOptions []byte) {
+func unmarshalMessageExtensionRange(b []byte) (r [2]protoreflect.FieldNumber, rawOptions []byte) {
for len(b) > 0 {
num, typ, n := protowire.ConsumeTag(b)
b = b[n:]
@@ -391,9 +391,9 @@ func unmarshalMessageExtensionRange(b []byte) (r [2]pref.FieldNumber, rawOptions
b = b[m:]
switch num {
case genid.DescriptorProto_ExtensionRange_Start_field_number:
- r[0] = pref.FieldNumber(v)
+ r[0] = protoreflect.FieldNumber(v)
case genid.DescriptorProto_ExtensionRange_End_field_number:
- r[1] = pref.FieldNumber(v)
+ r[1] = protoreflect.FieldNumber(v)
}
case protowire.BytesType:
v, m := protowire.ConsumeBytes(b)
@@ -410,7 +410,7 @@ func unmarshalMessageExtensionRange(b []byte) (r [2]pref.FieldNumber, rawOptions
return r, rawOptions
}
-func (fd *Field) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
+func (fd *Field) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
fd.L0.ParentFile = pf
fd.L0.Parent = pd
fd.L0.Index = i
@@ -426,11 +426,11 @@ func (fd *Field) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd pref.Des
b = b[m:]
switch num {
case genid.FieldDescriptorProto_Number_field_number:
- fd.L1.Number = pref.FieldNumber(v)
+ fd.L1.Number = protoreflect.FieldNumber(v)
case genid.FieldDescriptorProto_Label_field_number:
- fd.L1.Cardinality = pref.Cardinality(v)
+ fd.L1.Cardinality = protoreflect.Cardinality(v)
case genid.FieldDescriptorProto_Type_field_number:
- fd.L1.Kind = pref.Kind(v)
+ fd.L1.Kind = protoreflect.Kind(v)
case genid.FieldDescriptorProto_OneofIndex_field_number:
// In Message.unmarshalFull, we allocate slices for both
// the field and oneof descriptors before unmarshaling either
@@ -453,7 +453,7 @@ func (fd *Field) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd pref.Des
case genid.FieldDescriptorProto_JsonName_field_number:
fd.L1.StringName.InitJSON(sb.MakeString(v))
case genid.FieldDescriptorProto_DefaultValue_field_number:
- fd.L1.Default.val = pref.ValueOfBytes(v) // temporarily store as bytes; later resolved in resolveMessages
+ fd.L1.Default.val = protoreflect.ValueOfBytes(v) // temporarily store as bytes; later resolved in resolveMessages
case genid.FieldDescriptorProto_TypeName_field_number:
rawTypeName = v
case genid.FieldDescriptorProto_Options_field_number:
@@ -468,9 +468,9 @@ func (fd *Field) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd pref.Des
if rawTypeName != nil {
name := makeFullName(sb, rawTypeName)
switch fd.L1.Kind {
- case pref.EnumKind:
+ case protoreflect.EnumKind:
fd.L1.Enum = PlaceholderEnum(name)
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
fd.L1.Message = PlaceholderMessage(name)
}
}
@@ -504,7 +504,7 @@ func (fd *Field) unmarshalOptions(b []byte) {
}
}
-func (od *Oneof) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
+func (od *Oneof) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
od.L0.ParentFile = pf
od.L0.Parent = pd
od.L0.Index = i
@@ -553,7 +553,7 @@ func (xd *Extension) unmarshalFull(b []byte, sb *strs.Builder) {
case genid.FieldDescriptorProto_JsonName_field_number:
xd.L2.StringName.InitJSON(sb.MakeString(v))
case genid.FieldDescriptorProto_DefaultValue_field_number:
- xd.L2.Default.val = pref.ValueOfBytes(v) // temporarily store as bytes; later resolved in resolveExtensions
+ xd.L2.Default.val = protoreflect.ValueOfBytes(v) // temporarily store as bytes; later resolved in resolveExtensions
case genid.FieldDescriptorProto_TypeName_field_number:
rawTypeName = v
case genid.FieldDescriptorProto_Options_field_number:
@@ -568,9 +568,9 @@ func (xd *Extension) unmarshalFull(b []byte, sb *strs.Builder) {
if rawTypeName != nil {
name := makeFullName(sb, rawTypeName)
switch xd.L1.Kind {
- case pref.EnumKind:
+ case protoreflect.EnumKind:
xd.L2.Enum = PlaceholderEnum(name)
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
xd.L2.Message = PlaceholderMessage(name)
}
}
@@ -627,7 +627,7 @@ func (sd *Service) unmarshalFull(b []byte, sb *strs.Builder) {
sd.L2.Options = sd.L0.ParentFile.builder.optionsUnmarshaler(&descopts.Service, rawOptions)
}
-func (md *Method) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
+func (md *Method) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
md.L0.ParentFile = pf
md.L0.Parent = pd
md.L0.Index = i
@@ -680,18 +680,18 @@ func appendOptions(dst, src []byte) []byte {
//
// The type of message to unmarshal to is passed as a pointer since the
// vars in descopts may not yet be populated at the time this function is called.
-func (db *Builder) optionsUnmarshaler(p *pref.ProtoMessage, b []byte) func() pref.ProtoMessage {
+func (db *Builder) optionsUnmarshaler(p *protoreflect.ProtoMessage, b []byte) func() protoreflect.ProtoMessage {
if b == nil {
return nil
}
- var opts pref.ProtoMessage
+ var opts protoreflect.ProtoMessage
var once sync.Once
- return func() pref.ProtoMessage {
+ return func() protoreflect.ProtoMessage {
once.Do(func() {
if *p == nil {
panic("Descriptor.Options called without importing the descriptor package")
}
- opts = reflect.New(reflect.TypeOf(*p).Elem()).Interface().(pref.ProtoMessage)
+ opts = reflect.New(reflect.TypeOf(*p).Elem()).Interface().(protoreflect.ProtoMessage)
if err := (proto.UnmarshalOptions{
AllowPartial: true,
Resolver: db.TypeResolver,
diff --git a/internal/filedesc/desc_test.go b/internal/filedesc/desc_test.go
index 4f204f88..21919d1e 100644
--- a/internal/filedesc/desc_test.go
+++ b/internal/filedesc/desc_test.go
@@ -14,11 +14,11 @@ import (
"github.com/google/go-cmp/cmp"
- detrand "google.golang.org/protobuf/internal/detrand"
+ "google.golang.org/protobuf/internal/detrand"
"google.golang.org/protobuf/internal/filedesc"
"google.golang.org/protobuf/proto"
- pdesc "google.golang.org/protobuf/reflect/protodesc"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protodesc"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/descriptorpb"
)
@@ -46,44 +46,44 @@ func TestFile(t *testing.T) {
Field: []*descriptorpb.FieldDescriptorProto{{
Name: proto.String("field_one"),
Number: proto.Int32(1),
- Label: descriptorpb.FieldDescriptorProto_Label(pref.Optional).Enum(),
- Type: descriptorpb.FieldDescriptorProto_Type(pref.StringKind).Enum(),
+ Label: descriptorpb.FieldDescriptorProto_Label(protoreflect.Optional).Enum(),
+ Type: descriptorpb.FieldDescriptorProto_Type(protoreflect.StringKind).Enum(),
DefaultValue: proto.String("hello, \"world!\"\n"),
OneofIndex: proto.Int32(0),
}, {
Name: proto.String("field_two"),
JsonName: proto.String("Field2"),
Number: proto.Int32(2),
- Label: descriptorpb.FieldDescriptorProto_Label(pref.Optional).Enum(),
- Type: descriptorpb.FieldDescriptorProto_Type(pref.EnumKind).Enum(),
+ Label: descriptorpb.FieldDescriptorProto_Label(protoreflect.Optional).Enum(),
+ Type: descriptorpb.FieldDescriptorProto_Type(protoreflect.EnumKind).Enum(),
DefaultValue: proto.String("BAR"),
TypeName: proto.String(".test.E1"),
OneofIndex: proto.Int32(1),
}, {
Name: proto.String("field_three"),
Number: proto.Int32(3),
- Label: descriptorpb.FieldDescriptorProto_Label(pref.Optional).Enum(),
- Type: descriptorpb.FieldDescriptorProto_Type(pref.MessageKind).Enum(),
+ Label: descriptorpb.FieldDescriptorProto_Label(protoreflect.Optional).Enum(),
+ Type: descriptorpb.FieldDescriptorProto_Type(protoreflect.MessageKind).Enum(),
TypeName: proto.String(".test.C"),
OneofIndex: proto.Int32(1),
}, {
Name: proto.String("field_four"),
JsonName: proto.String("Field4"),
Number: proto.Int32(4),
- Label: descriptorpb.FieldDescriptorProto_Label(pref.Repeated).Enum(),
- Type: descriptorpb.FieldDescriptorProto_Type(pref.MessageKind).Enum(),
+ Label: descriptorpb.FieldDescriptorProto_Label(protoreflect.Repeated).Enum(),
+ Type: descriptorpb.FieldDescriptorProto_Type(protoreflect.MessageKind).Enum(),
TypeName: proto.String(".test.B.FieldFourEntry"),
}, {
Name: proto.String("field_five"),
Number: proto.Int32(5),
- Label: descriptorpb.FieldDescriptorProto_Label(pref.Repeated).Enum(),
- Type: descriptorpb.FieldDescriptorProto_Type(pref.Int32Kind).Enum(),
+ Label: descriptorpb.FieldDescriptorProto_Label(protoreflect.Repeated).Enum(),
+ Type: descriptorpb.FieldDescriptorProto_Type(protoreflect.Int32Kind).Enum(),
Options: &descriptorpb.FieldOptions{Packed: proto.Bool(true)},
}, {
Name: proto.String("field_six"),
Number: proto.Int32(6),
- Label: descriptorpb.FieldDescriptorProto_Label(pref.Required).Enum(),
- Type: descriptorpb.FieldDescriptorProto_Type(pref.BytesKind).Enum(),
+ Label: descriptorpb.FieldDescriptorProto_Label(protoreflect.Required).Enum(),
+ Type: descriptorpb.FieldDescriptorProto_Type(protoreflect.BytesKind).Enum(),
}},
OneofDecl: []*descriptorpb.OneofDescriptorProto{
{
@@ -110,13 +110,13 @@ func TestFile(t *testing.T) {
Field: []*descriptorpb.FieldDescriptorProto{{
Name: proto.String("key"),
Number: proto.Int32(1),
- Label: descriptorpb.FieldDescriptorProto_Label(pref.Optional).Enum(),
- Type: descriptorpb.FieldDescriptorProto_Type(pref.StringKind).Enum(),
+ Label: descriptorpb.FieldDescriptorProto_Label(protoreflect.Optional).Enum(),
+ Type: descriptorpb.FieldDescriptorProto_Type(protoreflect.StringKind).Enum(),
}, {
Name: proto.String("value"),
Number: proto.Int32(2),
- Label: descriptorpb.FieldDescriptorProto_Label(pref.Optional).Enum(),
- Type: descriptorpb.FieldDescriptorProto_Type(pref.MessageKind).Enum(),
+ Label: descriptorpb.FieldDescriptorProto_Label(protoreflect.Optional).Enum(),
+ Type: descriptorpb.FieldDescriptorProto_Type(protoreflect.MessageKind).Enum(),
TypeName: proto.String(".test.B"),
}},
Options: &descriptorpb.MessageOptions{
@@ -130,8 +130,8 @@ func TestFile(t *testing.T) {
Field: []*descriptorpb.FieldDescriptorProto{{
Name: proto.String("F"),
Number: proto.Int32(1),
- Label: descriptorpb.FieldDescriptorProto_Label(pref.Required).Enum(),
- Type: descriptorpb.FieldDescriptorProto_Type(pref.BytesKind).Enum(),
+ Label: descriptorpb.FieldDescriptorProto_Label(protoreflect.Required).Enum(),
+ Type: descriptorpb.FieldDescriptorProto_Type(protoreflect.BytesKind).Enum(),
DefaultValue: proto.String(`dead\276\357`),
}},
}},
@@ -145,8 +145,8 @@ func TestFile(t *testing.T) {
Extension: []*descriptorpb.FieldDescriptorProto{{
Name: proto.String("X"),
Number: proto.Int32(1000),
- Label: descriptorpb.FieldDescriptorProto_Label(pref.Repeated).Enum(),
- Type: descriptorpb.FieldDescriptorProto_Type(pref.MessageKind).Enum(),
+ Label: descriptorpb.FieldDescriptorProto_Label(protoreflect.Repeated).Enum(),
+ Type: descriptorpb.FieldDescriptorProto_Type(protoreflect.MessageKind).Enum(),
TypeName: proto.String(".test.C"),
Extendee: proto.String(".test.B"),
}},
@@ -171,8 +171,8 @@ func TestFile(t *testing.T) {
Extension: []*descriptorpb.FieldDescriptorProto{{
Name: proto.String("X"),
Number: proto.Int32(1000),
- Label: descriptorpb.FieldDescriptorProto_Label(pref.Repeated).Enum(),
- Type: descriptorpb.FieldDescriptorProto_Type(pref.EnumKind).Enum(),
+ Label: descriptorpb.FieldDescriptorProto_Label(protoreflect.Repeated).Enum(),
+ Type: descriptorpb.FieldDescriptorProto_Type(protoreflect.EnumKind).Enum(),
Options: &descriptorpb.FieldOptions{Packed: proto.Bool(true)},
TypeName: proto.String(".test.E1"),
Extendee: proto.String(".test.B"),
@@ -190,7 +190,7 @@ func TestFile(t *testing.T) {
}},
}},
}
- fd1, err := pdesc.NewFile(f1, nil)
+ fd1, err := protodesc.NewFile(f1, nil)
if err != nil {
t.Fatalf("protodesc.NewFile() error: %v", err)
}
@@ -203,7 +203,7 @@ func TestFile(t *testing.T) {
tests := []struct {
name string
- desc pref.FileDescriptor
+ desc protoreflect.FileDescriptor
}{
{"protodesc.NewFile", fd1},
{"filedesc.Builder.Build", fd2},
@@ -220,28 +220,28 @@ func TestFile(t *testing.T) {
}
}
-func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
+func testFileAccessors(t *testing.T, fd protoreflect.FileDescriptor) {
// Represent the descriptor as a map where each key is an accessor method
// and the value is either the wanted tail value or another accessor map.
type M = map[string]interface{}
want := M{
"Parent": nil,
"Index": 0,
- "Syntax": pref.Proto2,
- "Name": pref.Name("test"),
- "FullName": pref.FullName("test"),
+ "Syntax": protoreflect.Proto2,
+ "Name": protoreflect.Name("test"),
+ "FullName": protoreflect.FullName("test"),
"Path": "path/to/file.proto",
- "Package": pref.FullName("test"),
+ "Package": protoreflect.FullName("test"),
"IsPlaceholder": false,
"Options": &descriptorpb.FileOptions{Deprecated: proto.Bool(true)},
"Messages": M{
"Len": 3,
"Get:0": M{
- "Parent": M{"FullName": pref.FullName("test")},
+ "Parent": M{"FullName": protoreflect.FullName("test")},
"Index": 0,
- "Syntax": pref.Proto2,
- "Name": pref.Name("A"),
- "FullName": pref.FullName("test.A"),
+ "Syntax": protoreflect.Proto2,
+ "Name": protoreflect.Name("A"),
+ "FullName": protoreflect.FullName("test.A"),
"IsPlaceholder": false,
"IsMapEntry": false,
"Options": &descriptorpb.MessageOptions{
@@ -255,27 +255,27 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
"Extensions": M{"Len": 0},
},
"ByName:B": M{
- "Name": pref.Name("B"),
+ "Name": protoreflect.Name("B"),
"Index": 1,
"Fields": M{
"Len": 6,
"ByJSONName:field_one": nil,
"ByJSONName:fieldOne": M{
- "Name": pref.Name("field_one"),
+ "Name": protoreflect.Name("field_one"),
"Index": 0,
"JSONName": "fieldOne",
"Default": "hello, \"world!\"\n",
- "ContainingOneof": M{"Name": pref.Name("O1"), "IsPlaceholder": false},
- "ContainingMessage": M{"FullName": pref.FullName("test.B")},
+ "ContainingOneof": M{"Name": protoreflect.Name("O1"), "IsPlaceholder": false},
+ "ContainingMessage": M{"FullName": protoreflect.FullName("test.B")},
},
"ByJSONName:fieldTwo": nil,
"ByJSONName:Field2": M{
- "Name": pref.Name("field_two"),
+ "Name": protoreflect.Name("field_two"),
"Index": 1,
"HasJSONName": true,
"JSONName": "Field2",
- "Default": pref.EnumNumber(1),
- "ContainingOneof": M{"Name": pref.Name("O2"), "IsPlaceholder": false},
+ "Default": protoreflect.EnumNumber(1),
+ "ContainingOneof": M{"Name": protoreflect.Name("O2"), "IsPlaceholder": false},
},
"ByName:fieldThree": nil,
"ByName:field_three": M{
@@ -283,31 +283,31 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
"IsMap": false,
"MapKey": nil,
"MapValue": nil,
- "Message": M{"FullName": pref.FullName("test.C"), "IsPlaceholder": false},
- "ContainingOneof": M{"Name": pref.Name("O2"), "IsPlaceholder": false},
- "ContainingMessage": M{"FullName": pref.FullName("test.B")},
+ "Message": M{"FullName": protoreflect.FullName("test.C"), "IsPlaceholder": false},
+ "ContainingOneof": M{"Name": protoreflect.Name("O2"), "IsPlaceholder": false},
+ "ContainingMessage": M{"FullName": protoreflect.FullName("test.B")},
},
"ByNumber:12": nil,
"ByNumber:4": M{
- "Cardinality": pref.Repeated,
+ "Cardinality": protoreflect.Repeated,
"IsExtension": false,
"IsList": false,
"IsMap": true,
- "MapKey": M{"Kind": pref.StringKind},
- "MapValue": M{"Kind": pref.MessageKind, "Message": M{"FullName": pref.FullName("test.B")}},
+ "MapKey": M{"Kind": protoreflect.StringKind},
+ "MapValue": M{"Kind": protoreflect.MessageKind, "Message": M{"FullName": protoreflect.FullName("test.B")}},
"Default": nil,
- "Message": M{"FullName": pref.FullName("test.B.FieldFourEntry"), "IsPlaceholder": false},
+ "Message": M{"FullName": protoreflect.FullName("test.B.FieldFourEntry"), "IsPlaceholder": false},
},
"ByNumber:5": M{
- "Cardinality": pref.Repeated,
- "Kind": pref.Int32Kind,
+ "Cardinality": protoreflect.Repeated,
+ "Kind": protoreflect.Int32Kind,
"IsPacked": true,
"IsList": true,
"IsMap": false,
"Default": nil,
},
"ByNumber:6": M{
- "Cardinality": pref.Required,
+ "Cardinality": protoreflect.Required,
"Default": []byte(nil),
"ContainingOneof": nil,
},
@@ -316,7 +316,7 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
"Len": 2,
"ByName:O0": nil,
"ByName:O1": M{
- "FullName": pref.FullName("test.B.O1"),
+ "FullName": protoreflect.FullName("test.B.O1"),
"Index": 0,
"Options": &descriptorpb.OneofOptions{
UninterpretedOption: []*descriptorpb.UninterpretedOption{
@@ -325,28 +325,28 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
},
"Fields": M{
"Len": 1,
- "Get:0": M{"FullName": pref.FullName("test.B.field_one")},
+ "Get:0": M{"FullName": protoreflect.FullName("test.B.field_one")},
},
},
"Get:1": M{
- "FullName": pref.FullName("test.B.O2"),
+ "FullName": protoreflect.FullName("test.B.O2"),
"Index": 1,
"Fields": M{
"Len": 2,
- "ByName:field_two": M{"Name": pref.Name("field_two")},
- "Get:1": M{"Name": pref.Name("field_three")},
+ "ByName:field_two": M{"Name": protoreflect.Name("field_two")},
+ "Get:1": M{"Name": protoreflect.Name("field_three")},
},
},
},
"ReservedNames": M{
"Len": 2,
- "Get:0": pref.Name("fizz"),
+ "Get:0": protoreflect.Name("fizz"),
"Has:buzz": true,
"Has:noexist": false,
},
"ReservedRanges": M{
"Len": 2,
- "Get:0": [2]pref.FieldNumber{100, 200},
+ "Get:0": [2]protoreflect.FieldNumber{100, 200},
"Has:99": false,
"Has:100": true,
"Has:150": true,
@@ -357,13 +357,13 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
},
"RequiredNumbers": M{
"Len": 1,
- "Get:0": pref.FieldNumber(6),
+ "Get:0": protoreflect.FieldNumber(6),
"Has:1": false,
"Has:6": true,
},
"ExtensionRanges": M{
"Len": 2,
- "Get:0": [2]pref.FieldNumber{1000, 2000},
+ "Get:0": [2]protoreflect.FieldNumber{1000, 2000},
"Has:999": false,
"Has:1000": true,
"Has:1500": true,
@@ -379,13 +379,13 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
"Fields": M{
"Len": 2,
"ByNumber:1": M{
- "Parent": M{"FullName": pref.FullName("test.B.FieldFourEntry")},
+ "Parent": M{"FullName": protoreflect.FullName("test.B.FieldFourEntry")},
"Index": 0,
- "Name": pref.Name("key"),
- "FullName": pref.FullName("test.B.FieldFourEntry.key"),
- "Number": pref.FieldNumber(1),
- "Cardinality": pref.Optional,
- "Kind": pref.StringKind,
+ "Name": protoreflect.Name("key"),
+ "FullName": protoreflect.FullName("test.B.FieldFourEntry.key"),
+ "Number": protoreflect.FieldNumber(1),
+ "Cardinality": protoreflect.Optional,
+ "Kind": protoreflect.StringKind,
"Options": (*descriptorpb.FieldOptions)(nil),
"HasJSONName": false,
"JSONName": "key",
@@ -396,18 +396,18 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
"IsWeak": false,
"Default": "",
"ContainingOneof": nil,
- "ContainingMessage": M{"FullName": pref.FullName("test.B.FieldFourEntry")},
+ "ContainingMessage": M{"FullName": protoreflect.FullName("test.B.FieldFourEntry")},
"Message": nil,
"Enum": nil,
},
"ByNumber:2": M{
- "Parent": M{"FullName": pref.FullName("test.B.FieldFourEntry")},
+ "Parent": M{"FullName": protoreflect.FullName("test.B.FieldFourEntry")},
"Index": 1,
- "Name": pref.Name("value"),
- "FullName": pref.FullName("test.B.FieldFourEntry.value"),
- "Number": pref.FieldNumber(2),
- "Cardinality": pref.Optional,
- "Kind": pref.MessageKind,
+ "Name": protoreflect.Name("value"),
+ "FullName": protoreflect.FullName("test.B.FieldFourEntry.value"),
+ "Number": protoreflect.FieldNumber(2),
+ "Cardinality": protoreflect.Optional,
+ "Kind": protoreflect.MessageKind,
"JSONName": "value",
"IsPacked": false,
"IsList": false,
@@ -416,8 +416,8 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
"IsWeak": false,
"Default": nil,
"ContainingOneof": nil,
- "ContainingMessage": M{"FullName": pref.FullName("test.B.FieldFourEntry")},
- "Message": M{"FullName": pref.FullName("test.B"), "IsPlaceholder": false},
+ "ContainingMessage": M{"FullName": protoreflect.FullName("test.B.FieldFourEntry")},
+ "Message": M{"FullName": protoreflect.FullName("test.B"), "IsPlaceholder": false},
"Enum": nil,
},
"ByNumber:3": nil,
@@ -426,46 +426,46 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
},
},
"Get:2": M{
- "Name": pref.Name("C"),
+ "Name": protoreflect.Name("C"),
"Index": 2,
"Messages": M{
"Len": 1,
- "Get:0": M{"FullName": pref.FullName("test.C.A")},
+ "Get:0": M{"FullName": protoreflect.FullName("test.C.A")},
},
"Enums": M{
"Len": 1,
- "Get:0": M{"FullName": pref.FullName("test.C.E1")},
+ "Get:0": M{"FullName": protoreflect.FullName("test.C.E1")},
},
"Extensions": M{
"Len": 1,
- "Get:0": M{"FullName": pref.FullName("test.C.X")},
+ "Get:0": M{"FullName": protoreflect.FullName("test.C.X")},
},
},
},
"Enums": M{
"Len": 1,
"Get:0": M{
- "Name": pref.Name("E1"),
+ "Name": protoreflect.Name("E1"),
"Options": &descriptorpb.EnumOptions{Deprecated: proto.Bool(true)},
"Values": M{
"Len": 2,
"ByName:Foo": nil,
"ByName:FOO": M{
- "FullName": pref.FullName("test.FOO"),
+ "FullName": protoreflect.FullName("test.FOO"),
"Options": &descriptorpb.EnumValueOptions{Deprecated: proto.Bool(true)},
},
"ByNumber:2": nil,
- "ByNumber:1": M{"FullName": pref.FullName("test.BAR")},
+ "ByNumber:1": M{"FullName": protoreflect.FullName("test.BAR")},
},
"ReservedNames": M{
"Len": 2,
- "Get:0": pref.Name("FIZZ"),
+ "Get:0": protoreflect.Name("FIZZ"),
"Has:BUZZ": true,
"Has:NOEXIST": false,
},
"ReservedRanges": M{
"Len": 2,
- "Get:0": [2]pref.EnumNumber{10, 19},
+ "Get:0": [2]protoreflect.EnumNumber{10, 19},
"Has:9": false,
"Has:10": true,
"Has:15": true,
@@ -479,10 +479,10 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
"Extensions": M{
"Len": 1,
"ByName:X": M{
- "Name": pref.Name("X"),
- "Number": pref.FieldNumber(1000),
- "Cardinality": pref.Repeated,
- "Kind": pref.EnumKind,
+ "Name": protoreflect.Name("X"),
+ "Number": protoreflect.FieldNumber(1000),
+ "Cardinality": protoreflect.Repeated,
+ "Kind": protoreflect.EnumKind,
"IsExtension": true,
"IsPacked": true,
"IsList": true,
@@ -490,8 +490,8 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
"MapKey": nil,
"MapValue": nil,
"ContainingOneof": nil,
- "ContainingMessage": M{"FullName": pref.FullName("test.B"), "IsPlaceholder": false},
- "Enum": M{"FullName": pref.FullName("test.E1"), "IsPlaceholder": false},
+ "ContainingMessage": M{"FullName": protoreflect.FullName("test.B"), "IsPlaceholder": false},
+ "Enum": M{"FullName": protoreflect.FullName("test.E1"), "IsPlaceholder": false},
"Options": &descriptorpb.FieldOptions{Packed: proto.Bool(true)},
},
},
@@ -499,18 +499,18 @@ func testFileAccessors(t *testing.T, fd pref.FileDescriptor) {
"Len": 1,
"ByName:s": nil,
"ByName:S": M{
- "Parent": M{"FullName": pref.FullName("test")},
- "Name": pref.Name("S"),
- "FullName": pref.FullName("test.S"),
+ "Parent": M{"FullName": protoreflect.FullName("test")},
+ "Name": protoreflect.Name("S"),
+ "FullName": protoreflect.FullName("test.S"),
"Options": &descriptorpb.ServiceOptions{Deprecated: proto.Bool(true)},
"Methods": M{
"Len": 1,
"Get:0": M{
- "Parent": M{"FullName": pref.FullName("test.S")},
- "Name": pref.Name("M"),
- "FullName": pref.FullName("test.S.M"),
- "Input": M{"FullName": pref.FullName("test.A"), "IsPlaceholder": false},
- "Output": M{"FullName": pref.FullName("test.C.A"), "IsPlaceholder": false},
+ "Parent": M{"FullName": protoreflect.FullName("test.S")},
+ "Name": protoreflect.Name("M"),
+ "FullName": protoreflect.FullName("test.S.M"),
+ "Input": M{"FullName": protoreflect.FullName("test.A"), "IsPlaceholder": false},
+ "Output": M{"FullName": protoreflect.FullName("test.C.A"), "IsPlaceholder": false},
"IsStreamingClient": true,
"IsStreamingServer": true,
"Options": &descriptorpb.MethodOptions{Deprecated: proto.Bool(true)},
@@ -572,7 +572,7 @@ func checkAccessors(t *testing.T, p string, rv reflect.Value, want map[string]in
}
got := rets[0].Interface()
- if pv, ok := got.(pref.Value); ok {
+ if pv, ok := got.(protoreflect.Value); ok {
got = pv.Interface()
}
@@ -599,7 +599,7 @@ func checkAccessors(t *testing.T, p string, rv reflect.Value, want map[string]in
}
}
-func testFileFormat(t *testing.T, fd pref.FileDescriptor) {
+func testFileFormat(t *testing.T, fd protoreflect.FileDescriptor) {
const wantFileDescriptor = `FileDescriptor{
Syntax: proto2
Path: "path/to/file.proto"
diff --git a/internal/filedesc/placeholder.go b/internal/filedesc/placeholder.go
index dbf2c605..28240ebc 100644
--- a/internal/filedesc/placeholder.go
+++ b/internal/filedesc/placeholder.go
@@ -7,7 +7,7 @@ package filedesc
import (
"google.golang.org/protobuf/internal/descopts"
"google.golang.org/protobuf/internal/pragma"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
var (
@@ -30,78 +30,80 @@ var (
// PlaceholderFile is a placeholder, representing only the file path.
type PlaceholderFile string
-func (f PlaceholderFile) ParentFile() pref.FileDescriptor { return f }
-func (f PlaceholderFile) Parent() pref.Descriptor { return nil }
-func (f PlaceholderFile) Index() int { return 0 }
-func (f PlaceholderFile) Syntax() pref.Syntax { return 0 }
-func (f PlaceholderFile) Name() pref.Name { return "" }
-func (f PlaceholderFile) FullName() pref.FullName { return "" }
-func (f PlaceholderFile) IsPlaceholder() bool { return true }
-func (f PlaceholderFile) Options() pref.ProtoMessage { return descopts.File }
-func (f PlaceholderFile) Path() string { return string(f) }
-func (f PlaceholderFile) Package() pref.FullName { return "" }
-func (f PlaceholderFile) Imports() pref.FileImports { return emptyFiles }
-func (f PlaceholderFile) Messages() pref.MessageDescriptors { return emptyMessages }
-func (f PlaceholderFile) Enums() pref.EnumDescriptors { return emptyEnums }
-func (f PlaceholderFile) Extensions() pref.ExtensionDescriptors { return emptyExtensions }
-func (f PlaceholderFile) Services() pref.ServiceDescriptors { return emptyServices }
-func (f PlaceholderFile) SourceLocations() pref.SourceLocations { return emptySourceLocations }
-func (f PlaceholderFile) ProtoType(pref.FileDescriptor) { return }
-func (f PlaceholderFile) ProtoInternal(pragma.DoNotImplement) { return }
+func (f PlaceholderFile) ParentFile() protoreflect.FileDescriptor { return f }
+func (f PlaceholderFile) Parent() protoreflect.Descriptor { return nil }
+func (f PlaceholderFile) Index() int { return 0 }
+func (f PlaceholderFile) Syntax() protoreflect.Syntax { return 0 }
+func (f PlaceholderFile) Name() protoreflect.Name { return "" }
+func (f PlaceholderFile) FullName() protoreflect.FullName { return "" }
+func (f PlaceholderFile) IsPlaceholder() bool { return true }
+func (f PlaceholderFile) Options() protoreflect.ProtoMessage { return descopts.File }
+func (f PlaceholderFile) Path() string { return string(f) }
+func (f PlaceholderFile) Package() protoreflect.FullName { return "" }
+func (f PlaceholderFile) Imports() protoreflect.FileImports { return emptyFiles }
+func (f PlaceholderFile) Messages() protoreflect.MessageDescriptors { return emptyMessages }
+func (f PlaceholderFile) Enums() protoreflect.EnumDescriptors { return emptyEnums }
+func (f PlaceholderFile) Extensions() protoreflect.ExtensionDescriptors { return emptyExtensions }
+func (f PlaceholderFile) Services() protoreflect.ServiceDescriptors { return emptyServices }
+func (f PlaceholderFile) SourceLocations() protoreflect.SourceLocations { return emptySourceLocations }
+func (f PlaceholderFile) ProtoType(protoreflect.FileDescriptor) { return }
+func (f PlaceholderFile) ProtoInternal(pragma.DoNotImplement) { return }
// PlaceholderEnum is a placeholder, representing only the full name.
-type PlaceholderEnum pref.FullName
+type PlaceholderEnum protoreflect.FullName
-func (e PlaceholderEnum) ParentFile() pref.FileDescriptor { return nil }
-func (e PlaceholderEnum) Parent() pref.Descriptor { return nil }
-func (e PlaceholderEnum) Index() int { return 0 }
-func (e PlaceholderEnum) Syntax() pref.Syntax { return 0 }
-func (e PlaceholderEnum) Name() pref.Name { return pref.FullName(e).Name() }
-func (e PlaceholderEnum) FullName() pref.FullName { return pref.FullName(e) }
-func (e PlaceholderEnum) IsPlaceholder() bool { return true }
-func (e PlaceholderEnum) Options() pref.ProtoMessage { return descopts.Enum }
-func (e PlaceholderEnum) Values() pref.EnumValueDescriptors { return emptyEnumValues }
-func (e PlaceholderEnum) ReservedNames() pref.Names { return emptyNames }
-func (e PlaceholderEnum) ReservedRanges() pref.EnumRanges { return emptyEnumRanges }
-func (e PlaceholderEnum) ProtoType(pref.EnumDescriptor) { return }
-func (e PlaceholderEnum) ProtoInternal(pragma.DoNotImplement) { return }
+func (e PlaceholderEnum) ParentFile() protoreflect.FileDescriptor { return nil }
+func (e PlaceholderEnum) Parent() protoreflect.Descriptor { return nil }
+func (e PlaceholderEnum) Index() int { return 0 }
+func (e PlaceholderEnum) Syntax() protoreflect.Syntax { return 0 }
+func (e PlaceholderEnum) Name() protoreflect.Name { return protoreflect.FullName(e).Name() }
+func (e PlaceholderEnum) FullName() protoreflect.FullName { return protoreflect.FullName(e) }
+func (e PlaceholderEnum) IsPlaceholder() bool { return true }
+func (e PlaceholderEnum) Options() protoreflect.ProtoMessage { return descopts.Enum }
+func (e PlaceholderEnum) Values() protoreflect.EnumValueDescriptors { return emptyEnumValues }
+func (e PlaceholderEnum) ReservedNames() protoreflect.Names { return emptyNames }
+func (e PlaceholderEnum) ReservedRanges() protoreflect.EnumRanges { return emptyEnumRanges }
+func (e PlaceholderEnum) ProtoType(protoreflect.EnumDescriptor) { return }
+func (e PlaceholderEnum) ProtoInternal(pragma.DoNotImplement) { return }
// PlaceholderEnumValue is a placeholder, representing only the full name.
-type PlaceholderEnumValue pref.FullName
+type PlaceholderEnumValue protoreflect.FullName
-func (e PlaceholderEnumValue) ParentFile() pref.FileDescriptor { return nil }
-func (e PlaceholderEnumValue) Parent() pref.Descriptor { return nil }
-func (e PlaceholderEnumValue) Index() int { return 0 }
-func (e PlaceholderEnumValue) Syntax() pref.Syntax { return 0 }
-func (e PlaceholderEnumValue) Name() pref.Name { return pref.FullName(e).Name() }
-func (e PlaceholderEnumValue) FullName() pref.FullName { return pref.FullName(e) }
-func (e PlaceholderEnumValue) IsPlaceholder() bool { return true }
-func (e PlaceholderEnumValue) Options() pref.ProtoMessage { return descopts.EnumValue }
-func (e PlaceholderEnumValue) Number() pref.EnumNumber { return 0 }
-func (e PlaceholderEnumValue) ProtoType(pref.EnumValueDescriptor) { return }
-func (e PlaceholderEnumValue) ProtoInternal(pragma.DoNotImplement) { return }
+func (e PlaceholderEnumValue) ParentFile() protoreflect.FileDescriptor { return nil }
+func (e PlaceholderEnumValue) Parent() protoreflect.Descriptor { return nil }
+func (e PlaceholderEnumValue) Index() int { return 0 }
+func (e PlaceholderEnumValue) Syntax() protoreflect.Syntax { return 0 }
+func (e PlaceholderEnumValue) Name() protoreflect.Name { return protoreflect.FullName(e).Name() }
+func (e PlaceholderEnumValue) FullName() protoreflect.FullName { return protoreflect.FullName(e) }
+func (e PlaceholderEnumValue) IsPlaceholder() bool { return true }
+func (e PlaceholderEnumValue) Options() protoreflect.ProtoMessage { return descopts.EnumValue }
+func (e PlaceholderEnumValue) Number() protoreflect.EnumNumber { return 0 }
+func (e PlaceholderEnumValue) ProtoType(protoreflect.EnumValueDescriptor) { return }
+func (e PlaceholderEnumValue) ProtoInternal(pragma.DoNotImplement) { return }
// PlaceholderMessage is a placeholder, representing only the full name.
-type PlaceholderMessage pref.FullName
+type PlaceholderMessage protoreflect.FullName
-func (m PlaceholderMessage) ParentFile() pref.FileDescriptor { return nil }
-func (m PlaceholderMessage) Parent() pref.Descriptor { return nil }
-func (m PlaceholderMessage) Index() int { return 0 }
-func (m PlaceholderMessage) Syntax() pref.Syntax { return 0 }
-func (m PlaceholderMessage) Name() pref.Name { return pref.FullName(m).Name() }
-func (m PlaceholderMessage) FullName() pref.FullName { return pref.FullName(m) }
-func (m PlaceholderMessage) IsPlaceholder() bool { return true }
-func (m PlaceholderMessage) Options() pref.ProtoMessage { return descopts.Message }
-func (m PlaceholderMessage) IsMapEntry() bool { return false }
-func (m PlaceholderMessage) Fields() pref.FieldDescriptors { return emptyFields }
-func (m PlaceholderMessage) Oneofs() pref.OneofDescriptors { return emptyOneofs }
-func (m PlaceholderMessage) ReservedNames() pref.Names { return emptyNames }
-func (m PlaceholderMessage) ReservedRanges() pref.FieldRanges { return emptyFieldRanges }
-func (m PlaceholderMessage) RequiredNumbers() pref.FieldNumbers { return emptyFieldNumbers }
-func (m PlaceholderMessage) ExtensionRanges() pref.FieldRanges { return emptyFieldRanges }
-func (m PlaceholderMessage) ExtensionRangeOptions(int) pref.ProtoMessage { panic("index out of range") }
-func (m PlaceholderMessage) Messages() pref.MessageDescriptors { return emptyMessages }
-func (m PlaceholderMessage) Enums() pref.EnumDescriptors { return emptyEnums }
-func (m PlaceholderMessage) Extensions() pref.ExtensionDescriptors { return emptyExtensions }
-func (m PlaceholderMessage) ProtoType(pref.MessageDescriptor) { return }
-func (m PlaceholderMessage) ProtoInternal(pragma.DoNotImplement) { return }
+func (m PlaceholderMessage) ParentFile() protoreflect.FileDescriptor { return nil }
+func (m PlaceholderMessage) Parent() protoreflect.Descriptor { return nil }
+func (m PlaceholderMessage) Index() int { return 0 }
+func (m PlaceholderMessage) Syntax() protoreflect.Syntax { return 0 }
+func (m PlaceholderMessage) Name() protoreflect.Name { return protoreflect.FullName(m).Name() }
+func (m PlaceholderMessage) FullName() protoreflect.FullName { return protoreflect.FullName(m) }
+func (m PlaceholderMessage) IsPlaceholder() bool { return true }
+func (m PlaceholderMessage) Options() protoreflect.ProtoMessage { return descopts.Message }
+func (m PlaceholderMessage) IsMapEntry() bool { return false }
+func (m PlaceholderMessage) Fields() protoreflect.FieldDescriptors { return emptyFields }
+func (m PlaceholderMessage) Oneofs() protoreflect.OneofDescriptors { return emptyOneofs }
+func (m PlaceholderMessage) ReservedNames() protoreflect.Names { return emptyNames }
+func (m PlaceholderMessage) ReservedRanges() protoreflect.FieldRanges { return emptyFieldRanges }
+func (m PlaceholderMessage) RequiredNumbers() protoreflect.FieldNumbers { return emptyFieldNumbers }
+func (m PlaceholderMessage) ExtensionRanges() protoreflect.FieldRanges { return emptyFieldRanges }
+func (m PlaceholderMessage) ExtensionRangeOptions(int) protoreflect.ProtoMessage {
+ panic("index out of range")
+}
+func (m PlaceholderMessage) Messages() protoreflect.MessageDescriptors { return emptyMessages }
+func (m PlaceholderMessage) Enums() protoreflect.EnumDescriptors { return emptyEnums }
+func (m PlaceholderMessage) Extensions() protoreflect.ExtensionDescriptors { return emptyExtensions }
+func (m PlaceholderMessage) ProtoType(protoreflect.MessageDescriptor) { return }
+func (m PlaceholderMessage) ProtoInternal(pragma.DoNotImplement) { return }
diff --git a/internal/filetype/build.go b/internal/filetype/build.go
index 0a0dd35d..3744dc84 100644
--- a/internal/filetype/build.go
+++ b/internal/filetype/build.go
@@ -10,10 +10,10 @@ import (
"reflect"
"google.golang.org/protobuf/internal/descopts"
- fdesc "google.golang.org/protobuf/internal/filedesc"
+ "google.golang.org/protobuf/internal/filedesc"
pimpl "google.golang.org/protobuf/internal/impl"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoregistry"
)
// Builder constructs type descriptors from a raw file descriptor
@@ -52,7 +52,7 @@ import (
// that children themselves may have.
type Builder struct {
// File is the underlying file descriptor builder.
- File fdesc.Builder
+ File filedesc.Builder
// GoTypes is a unique set of the Go types for all declarations and
// dependencies. Each type is represented as a zero value of the Go type.
@@ -108,22 +108,22 @@ type Builder struct {
// TypeRegistry is the registry to register each type descriptor.
// If nil, it uses protoregistry.GlobalTypes.
TypeRegistry interface {
- RegisterMessage(pref.MessageType) error
- RegisterEnum(pref.EnumType) error
- RegisterExtension(pref.ExtensionType) error
+ RegisterMessage(protoreflect.MessageType) error
+ RegisterEnum(protoreflect.EnumType) error
+ RegisterExtension(protoreflect.ExtensionType) error
}
}
// Out is the output of the builder.
type Out struct {
- File pref.FileDescriptor
+ File protoreflect.FileDescriptor
}
func (tb Builder) Build() (out Out) {
// Replace the resolver with one that resolves dependencies by index,
// which is faster and more reliable than relying on the global registry.
if tb.File.FileRegistry == nil {
- tb.File.FileRegistry = preg.GlobalFiles
+ tb.File.FileRegistry = protoregistry.GlobalFiles
}
tb.File.FileRegistry = &resolverByIndex{
goTypes: tb.GoTypes,
@@ -133,7 +133,7 @@ func (tb Builder) Build() (out Out) {
// Initialize registry if unpopulated.
if tb.TypeRegistry == nil {
- tb.TypeRegistry = preg.GlobalTypes
+ tb.TypeRegistry = protoregistry.GlobalTypes
}
fbOut := tb.File.Build()
@@ -183,23 +183,23 @@ func (tb Builder) Build() (out Out) {
for i := range fbOut.Messages {
switch fbOut.Messages[i].Name() {
case "FileOptions":
- descopts.File = messageGoTypes[i].(pref.ProtoMessage)
+ descopts.File = messageGoTypes[i].(protoreflect.ProtoMessage)
case "EnumOptions":
- descopts.Enum = messageGoTypes[i].(pref.ProtoMessage)
+ descopts.Enum = messageGoTypes[i].(protoreflect.ProtoMessage)
case "EnumValueOptions":
- descopts.EnumValue = messageGoTypes[i].(pref.ProtoMessage)
+ descopts.EnumValue = messageGoTypes[i].(protoreflect.ProtoMessage)
case "MessageOptions":
- descopts.Message = messageGoTypes[i].(pref.ProtoMessage)
+ descopts.Message = messageGoTypes[i].(protoreflect.ProtoMessage)
case "FieldOptions":
- descopts.Field = messageGoTypes[i].(pref.ProtoMessage)
+ descopts.Field = messageGoTypes[i].(protoreflect.ProtoMessage)
case "OneofOptions":
- descopts.Oneof = messageGoTypes[i].(pref.ProtoMessage)
+ descopts.Oneof = messageGoTypes[i].(protoreflect.ProtoMessage)
case "ExtensionRangeOptions":
- descopts.ExtensionRange = messageGoTypes[i].(pref.ProtoMessage)
+ descopts.ExtensionRange = messageGoTypes[i].(protoreflect.ProtoMessage)
case "ServiceOptions":
- descopts.Service = messageGoTypes[i].(pref.ProtoMessage)
+ descopts.Service = messageGoTypes[i].(protoreflect.ProtoMessage)
case "MethodOptions":
- descopts.Method = messageGoTypes[i].(pref.ProtoMessage)
+ descopts.Method = messageGoTypes[i].(protoreflect.ProtoMessage)
}
}
}
@@ -216,11 +216,11 @@ func (tb Builder) Build() (out Out) {
const listExtDeps = 2
var goType reflect.Type
switch fbOut.Extensions[i].L1.Kind {
- case pref.EnumKind:
+ case protoreflect.EnumKind:
j := depIdxs.Get(tb.DependencyIndexes, listExtDeps, depIdx)
goType = reflect.TypeOf(tb.GoTypes[j])
depIdx++
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
j := depIdxs.Get(tb.DependencyIndexes, listExtDeps, depIdx)
goType = reflect.TypeOf(tb.GoTypes[j])
depIdx++
@@ -242,22 +242,22 @@ func (tb Builder) Build() (out Out) {
return out
}
-var goTypeForPBKind = map[pref.Kind]reflect.Type{
- pref.BoolKind: reflect.TypeOf(bool(false)),
- pref.Int32Kind: reflect.TypeOf(int32(0)),
- pref.Sint32Kind: reflect.TypeOf(int32(0)),
- pref.Sfixed32Kind: reflect.TypeOf(int32(0)),
- pref.Int64Kind: reflect.TypeOf(int64(0)),
- pref.Sint64Kind: reflect.TypeOf(int64(0)),
- pref.Sfixed64Kind: reflect.TypeOf(int64(0)),
- pref.Uint32Kind: reflect.TypeOf(uint32(0)),
- pref.Fixed32Kind: reflect.TypeOf(uint32(0)),
- pref.Uint64Kind: reflect.TypeOf(uint64(0)),
- pref.Fixed64Kind: reflect.TypeOf(uint64(0)),
- pref.FloatKind: reflect.TypeOf(float32(0)),
- pref.DoubleKind: reflect.TypeOf(float64(0)),
- pref.StringKind: reflect.TypeOf(string("")),
- pref.BytesKind: reflect.TypeOf([]byte(nil)),
+var goTypeForPBKind = map[protoreflect.Kind]reflect.Type{
+ protoreflect.BoolKind: reflect.TypeOf(bool(false)),
+ protoreflect.Int32Kind: reflect.TypeOf(int32(0)),
+ protoreflect.Sint32Kind: reflect.TypeOf(int32(0)),
+ protoreflect.Sfixed32Kind: reflect.TypeOf(int32(0)),
+ protoreflect.Int64Kind: reflect.TypeOf(int64(0)),
+ protoreflect.Sint64Kind: reflect.TypeOf(int64(0)),
+ protoreflect.Sfixed64Kind: reflect.TypeOf(int64(0)),
+ protoreflect.Uint32Kind: reflect.TypeOf(uint32(0)),
+ protoreflect.Fixed32Kind: reflect.TypeOf(uint32(0)),
+ protoreflect.Uint64Kind: reflect.TypeOf(uint64(0)),
+ protoreflect.Fixed64Kind: reflect.TypeOf(uint64(0)),
+ protoreflect.FloatKind: reflect.TypeOf(float32(0)),
+ protoreflect.DoubleKind: reflect.TypeOf(float64(0)),
+ protoreflect.StringKind: reflect.TypeOf(string("")),
+ protoreflect.BytesKind: reflect.TypeOf([]byte(nil)),
}
type depIdxs []int32
@@ -274,13 +274,13 @@ type (
fileRegistry
}
fileRegistry interface {
- FindFileByPath(string) (pref.FileDescriptor, error)
- FindDescriptorByName(pref.FullName) (pref.Descriptor, error)
- RegisterFile(pref.FileDescriptor) error
+ FindFileByPath(string) (protoreflect.FileDescriptor, error)
+ FindDescriptorByName(protoreflect.FullName) (protoreflect.Descriptor, error)
+ RegisterFile(protoreflect.FileDescriptor) error
}
)
-func (r *resolverByIndex) FindEnumByIndex(i, j int32, es []fdesc.Enum, ms []fdesc.Message) pref.EnumDescriptor {
+func (r *resolverByIndex) FindEnumByIndex(i, j int32, es []filedesc.Enum, ms []filedesc.Message) protoreflect.EnumDescriptor {
if depIdx := int(r.depIdxs.Get(i, j)); int(depIdx) < len(es)+len(ms) {
return &es[depIdx]
} else {
@@ -288,7 +288,7 @@ func (r *resolverByIndex) FindEnumByIndex(i, j int32, es []fdesc.Enum, ms []fdes
}
}
-func (r *resolverByIndex) FindMessageByIndex(i, j int32, es []fdesc.Enum, ms []fdesc.Message) pref.MessageDescriptor {
+func (r *resolverByIndex) FindMessageByIndex(i, j int32, es []filedesc.Enum, ms []filedesc.Message) protoreflect.MessageDescriptor {
if depIdx := int(r.depIdxs.Get(i, j)); depIdx < len(es)+len(ms) {
return &ms[depIdx-len(es)]
} else {
diff --git a/internal/impl/api_export.go b/internal/impl/api_export.go
index abee5f30..a371f98d 100644
--- a/internal/impl/api_export.go
+++ b/internal/impl/api_export.go
@@ -12,8 +12,8 @@ import (
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/errors"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- piface "google.golang.org/protobuf/runtime/protoiface"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/runtime/protoiface"
)
// Export is a zero-length named type that exists only to export a set of
@@ -32,11 +32,11 @@ type enum = interface{}
// EnumOf returns the protoreflect.Enum interface over e.
// It returns nil if e is nil.
-func (Export) EnumOf(e enum) pref.Enum {
+func (Export) EnumOf(e enum) protoreflect.Enum {
switch e := e.(type) {
case nil:
return nil
- case pref.Enum:
+ case protoreflect.Enum:
return e
default:
return legacyWrapEnum(reflect.ValueOf(e))
@@ -45,11 +45,11 @@ func (Export) EnumOf(e enum) pref.Enum {
// EnumDescriptorOf returns the protoreflect.EnumDescriptor for e.
// It returns nil if e is nil.
-func (Export) EnumDescriptorOf(e enum) pref.EnumDescriptor {
+func (Export) EnumDescriptorOf(e enum) protoreflect.EnumDescriptor {
switch e := e.(type) {
case nil:
return nil
- case pref.Enum:
+ case protoreflect.Enum:
return e.Descriptor()
default:
return LegacyLoadEnumDesc(reflect.TypeOf(e))
@@ -58,11 +58,11 @@ func (Export) EnumDescriptorOf(e enum) pref.EnumDescriptor {
// EnumTypeOf returns the protoreflect.EnumType for e.
// It returns nil if e is nil.
-func (Export) EnumTypeOf(e enum) pref.EnumType {
+func (Export) EnumTypeOf(e enum) protoreflect.EnumType {
switch e := e.(type) {
case nil:
return nil
- case pref.Enum:
+ case protoreflect.Enum:
return e.Type()
default:
return legacyLoadEnumType(reflect.TypeOf(e))
@@ -71,7 +71,7 @@ func (Export) EnumTypeOf(e enum) pref.EnumType {
// EnumStringOf returns the enum value as a string, either as the name if
// the number is resolvable, or the number formatted as a string.
-func (Export) EnumStringOf(ed pref.EnumDescriptor, n pref.EnumNumber) string {
+func (Export) EnumStringOf(ed protoreflect.EnumDescriptor, n protoreflect.EnumNumber) string {
ev := ed.Values().ByNumber(n)
if ev != nil {
return string(ev.Name())
@@ -84,7 +84,7 @@ func (Export) EnumStringOf(ed pref.EnumDescriptor, n pref.EnumNumber) string {
type message = interface{}
// legacyMessageWrapper wraps a v2 message as a v1 message.
-type legacyMessageWrapper struct{ m pref.ProtoMessage }
+type legacyMessageWrapper struct{ m protoreflect.ProtoMessage }
func (m legacyMessageWrapper) Reset() { proto.Reset(m.m) }
func (m legacyMessageWrapper) String() string { return Export{}.MessageStringOf(m.m) }
@@ -92,30 +92,30 @@ func (m legacyMessageWrapper) ProtoMessage() {}
// ProtoMessageV1Of converts either a v1 or v2 message to a v1 message.
// It returns nil if m is nil.
-func (Export) ProtoMessageV1Of(m message) piface.MessageV1 {
+func (Export) ProtoMessageV1Of(m message) protoiface.MessageV1 {
switch mv := m.(type) {
case nil:
return nil
- case piface.MessageV1:
+ case protoiface.MessageV1:
return mv
case unwrapper:
return Export{}.ProtoMessageV1Of(mv.protoUnwrap())
- case pref.ProtoMessage:
+ case protoreflect.ProtoMessage:
return legacyMessageWrapper{mv}
default:
panic(fmt.Sprintf("message %T is neither a v1 or v2 Message", m))
}
}
-func (Export) protoMessageV2Of(m message) pref.ProtoMessage {
+func (Export) protoMessageV2Of(m message) protoreflect.ProtoMessage {
switch mv := m.(type) {
case nil:
return nil
- case pref.ProtoMessage:
+ case protoreflect.ProtoMessage:
return mv
case legacyMessageWrapper:
return mv.m
- case piface.MessageV1:
+ case protoiface.MessageV1:
return nil
default:
panic(fmt.Sprintf("message %T is neither a v1 or v2 Message", m))
@@ -124,7 +124,7 @@ func (Export) protoMessageV2Of(m message) pref.ProtoMessage {
// ProtoMessageV2Of converts either a v1 or v2 message to a v2 message.
// It returns nil if m is nil.
-func (Export) ProtoMessageV2Of(m message) pref.ProtoMessage {
+func (Export) ProtoMessageV2Of(m message) protoreflect.ProtoMessage {
if m == nil {
return nil
}
@@ -136,7 +136,7 @@ func (Export) ProtoMessageV2Of(m message) pref.ProtoMessage {
// MessageOf returns the protoreflect.Message interface over m.
// It returns nil if m is nil.
-func (Export) MessageOf(m message) pref.Message {
+func (Export) MessageOf(m message) protoreflect.Message {
if m == nil {
return nil
}
@@ -148,7 +148,7 @@ func (Export) MessageOf(m message) pref.Message {
// MessageDescriptorOf returns the protoreflect.MessageDescriptor for m.
// It returns nil if m is nil.
-func (Export) MessageDescriptorOf(m message) pref.MessageDescriptor {
+func (Export) MessageDescriptorOf(m message) protoreflect.MessageDescriptor {
if m == nil {
return nil
}
@@ -160,7 +160,7 @@ func (Export) MessageDescriptorOf(m message) pref.MessageDescriptor {
// MessageTypeOf returns the protoreflect.MessageType for m.
// It returns nil if m is nil.
-func (Export) MessageTypeOf(m message) pref.MessageType {
+func (Export) MessageTypeOf(m message) protoreflect.MessageType {
if m == nil {
return nil
}
@@ -172,6 +172,6 @@ func (Export) MessageTypeOf(m message) pref.MessageType {
// MessageStringOf returns the message value as a string,
// which is the message serialized in the protobuf text format.
-func (Export) MessageStringOf(m pref.ProtoMessage) string {
+func (Export) MessageStringOf(m protoreflect.ProtoMessage) string {
return prototext.MarshalOptions{Multiline: false}.Format(m)
}
diff --git a/internal/impl/checkinit.go b/internal/impl/checkinit.go
index b82341e5..bff041ed 100644
--- a/internal/impl/checkinit.go
+++ b/internal/impl/checkinit.go
@@ -8,18 +8,18 @@ import (
"sync"
"google.golang.org/protobuf/internal/errors"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- piface "google.golang.org/protobuf/runtime/protoiface"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/runtime/protoiface"
)
-func (mi *MessageInfo) checkInitialized(in piface.CheckInitializedInput) (piface.CheckInitializedOutput, error) {
+func (mi *MessageInfo) checkInitialized(in protoiface.CheckInitializedInput) (protoiface.CheckInitializedOutput, error) {
var p pointer
if ms, ok := in.Message.(*messageState); ok {
p = ms.pointer()
} else {
p = in.Message.(*messageReflectWrapper).pointer()
}
- return piface.CheckInitializedOutput{}, mi.checkInitializedPointer(p)
+ return protoiface.CheckInitializedOutput{}, mi.checkInitializedPointer(p)
}
func (mi *MessageInfo) checkInitializedPointer(p pointer) error {
@@ -90,7 +90,7 @@ var (
// needsInitCheck reports whether a message needs to be checked for partial initialization.
//
// It returns true if the message transitively includes any required or extension fields.
-func needsInitCheck(md pref.MessageDescriptor) bool {
+func needsInitCheck(md protoreflect.MessageDescriptor) bool {
if v, ok := needsInitCheckMap.Load(md); ok {
if has, ok := v.(bool); ok {
return has
@@ -101,7 +101,7 @@ func needsInitCheck(md pref.MessageDescriptor) bool {
return needsInitCheckLocked(md)
}
-func needsInitCheckLocked(md pref.MessageDescriptor) (has bool) {
+func needsInitCheckLocked(md protoreflect.MessageDescriptor) (has bool) {
if v, ok := needsInitCheckMap.Load(md); ok {
// If has is true, we've previously determined that this message
// needs init checks.
diff --git a/internal/impl/codec_extension.go b/internal/impl/codec_extension.go
index 08d35170..e74cefdc 100644
--- a/internal/impl/codec_extension.go
+++ b/internal/impl/codec_extension.go
@@ -10,7 +10,7 @@ import (
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/errors"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
type extensionFieldInfo struct {
@@ -23,7 +23,7 @@ type extensionFieldInfo struct {
var legacyExtensionFieldInfoCache sync.Map // map[protoreflect.ExtensionType]*extensionFieldInfo
-func getExtensionFieldInfo(xt pref.ExtensionType) *extensionFieldInfo {
+func getExtensionFieldInfo(xt protoreflect.ExtensionType) *extensionFieldInfo {
if xi, ok := xt.(*ExtensionInfo); ok {
xi.lazyInit()
return xi.info
@@ -32,7 +32,7 @@ func getExtensionFieldInfo(xt pref.ExtensionType) *extensionFieldInfo {
}
// legacyLoadExtensionFieldInfo dynamically loads a *ExtensionInfo for xt.
-func legacyLoadExtensionFieldInfo(xt pref.ExtensionType) *extensionFieldInfo {
+func legacyLoadExtensionFieldInfo(xt protoreflect.ExtensionType) *extensionFieldInfo {
if xi, ok := legacyExtensionFieldInfoCache.Load(xt); ok {
return xi.(*extensionFieldInfo)
}
@@ -43,7 +43,7 @@ func legacyLoadExtensionFieldInfo(xt pref.ExtensionType) *extensionFieldInfo {
return e
}
-func makeExtensionFieldInfo(xd pref.ExtensionDescriptor) *extensionFieldInfo {
+func makeExtensionFieldInfo(xd protoreflect.ExtensionDescriptor) *extensionFieldInfo {
var wiretag uint64
if !xd.IsPacked() {
wiretag = protowire.EncodeTag(xd.Number(), wireTypes[xd.Kind()])
@@ -59,10 +59,10 @@ func makeExtensionFieldInfo(xd pref.ExtensionDescriptor) *extensionFieldInfo {
// This is true for composite types, where we pass in a message, list, or map to fill in,
// and for enums, where we pass in a prototype value to specify the concrete enum type.
switch xd.Kind() {
- case pref.MessageKind, pref.GroupKind, pref.EnumKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind, protoreflect.EnumKind:
e.unmarshalNeedsValue = true
default:
- if xd.Cardinality() == pref.Repeated {
+ if xd.Cardinality() == protoreflect.Repeated {
e.unmarshalNeedsValue = true
}
}
@@ -73,21 +73,21 @@ type lazyExtensionValue struct {
atomicOnce uint32 // atomically set if value is valid
mu sync.Mutex
xi *extensionFieldInfo
- value pref.Value
+ value protoreflect.Value
b []byte
- fn func() pref.Value
+ fn func() protoreflect.Value
}
type ExtensionField struct {
- typ pref.ExtensionType
+ typ protoreflect.ExtensionType
// value is either the value of GetValue,
// or a *lazyExtensionValue that then returns the value of GetValue.
- value pref.Value
+ value protoreflect.Value
lazy *lazyExtensionValue
}
-func (f *ExtensionField) appendLazyBytes(xt pref.ExtensionType, xi *extensionFieldInfo, num protowire.Number, wtyp protowire.Type, b []byte) {
+func (f *ExtensionField) appendLazyBytes(xt protoreflect.ExtensionType, xi *extensionFieldInfo, num protowire.Number, wtyp protowire.Type, b []byte) {
if f.lazy == nil {
f.lazy = &lazyExtensionValue{xi: xi}
}
@@ -97,7 +97,7 @@ func (f *ExtensionField) appendLazyBytes(xt pref.ExtensionType, xi *extensionFie
f.lazy.b = append(f.lazy.b, b...)
}
-func (f *ExtensionField) canLazy(xt pref.ExtensionType) bool {
+func (f *ExtensionField) canLazy(xt protoreflect.ExtensionType) bool {
if f.typ == nil {
return true
}
@@ -154,7 +154,7 @@ func (f *ExtensionField) lazyInit() {
// Set sets the type and value of the extension field.
// This must not be called concurrently.
-func (f *ExtensionField) Set(t pref.ExtensionType, v pref.Value) {
+func (f *ExtensionField) Set(t protoreflect.ExtensionType, v protoreflect.Value) {
f.typ = t
f.value = v
f.lazy = nil
@@ -162,14 +162,14 @@ func (f *ExtensionField) Set(t pref.ExtensionType, v pref.Value) {
// SetLazy sets the type and a value that is to be lazily evaluated upon first use.
// This must not be called concurrently.
-func (f *ExtensionField) SetLazy(t pref.ExtensionType, fn func() pref.Value) {
+func (f *ExtensionField) SetLazy(t protoreflect.ExtensionType, fn func() protoreflect.Value) {
f.typ = t
f.lazy = &lazyExtensionValue{fn: fn}
}
// Value returns the value of the extension field.
// This may be called concurrently.
-func (f *ExtensionField) Value() pref.Value {
+func (f *ExtensionField) Value() protoreflect.Value {
if f.lazy != nil {
if atomic.LoadUint32(&f.lazy.atomicOnce) == 0 {
f.lazyInit()
@@ -181,7 +181,7 @@ func (f *ExtensionField) Value() pref.Value {
// Type returns the type of the extension field.
// This may be called concurrently.
-func (f ExtensionField) Type() pref.ExtensionType {
+func (f ExtensionField) Type() protoreflect.ExtensionType {
return f.typ
}
@@ -193,7 +193,7 @@ func (f ExtensionField) IsSet() bool {
// IsLazy reports whether a field is lazily encoded.
// It is exported for testing.
-func IsLazy(m pref.Message, fd pref.FieldDescriptor) bool {
+func IsLazy(m protoreflect.Message, fd protoreflect.FieldDescriptor) bool {
var mi *MessageInfo
var p pointer
switch m := m.(type) {
@@ -206,7 +206,7 @@ func IsLazy(m pref.Message, fd pref.FieldDescriptor) bool {
default:
return false
}
- xd, ok := fd.(pref.ExtensionTypeDescriptor)
+ xd, ok := fd.(protoreflect.ExtensionTypeDescriptor)
if !ok {
return false
}
diff --git a/internal/impl/codec_field.go b/internal/impl/codec_field.go
index cb4b482d..3fadd241 100644
--- a/internal/impl/codec_field.go
+++ b/internal/impl/codec_field.go
@@ -12,9 +12,9 @@ import (
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/errors"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- preg "google.golang.org/protobuf/reflect/protoregistry"
- piface "google.golang.org/protobuf/runtime/protoiface"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/runtime/protoiface"
)
type errInvalidUTF8 struct{}
@@ -30,7 +30,7 @@ func (errInvalidUTF8) Unwrap() error { return errors.Error }
// to the appropriate field-specific function as necessary.
//
// The unmarshal function is set on each field individually as usual.
-func (mi *MessageInfo) initOneofFieldCoders(od pref.OneofDescriptor, si structInfo) {
+func (mi *MessageInfo) initOneofFieldCoders(od protoreflect.OneofDescriptor, si structInfo) {
fs := si.oneofsByName[od.Name()]
ft := fs.Type
oneofFields := make(map[reflect.Type]*coderFieldInfo)
@@ -118,13 +118,13 @@ func (mi *MessageInfo) initOneofFieldCoders(od pref.OneofDescriptor, si structIn
}
}
-func makeWeakMessageFieldCoder(fd pref.FieldDescriptor) pointerCoderFuncs {
+func makeWeakMessageFieldCoder(fd protoreflect.FieldDescriptor) pointerCoderFuncs {
var once sync.Once
- var messageType pref.MessageType
+ var messageType protoreflect.MessageType
lazyInit := func() {
once.Do(func() {
messageName := fd.Message().FullName()
- messageType, _ = preg.GlobalTypes.FindMessageByName(messageName)
+ messageType, _ = protoregistry.GlobalTypes.FindMessageByName(messageName)
})
}
@@ -190,7 +190,7 @@ func makeWeakMessageFieldCoder(fd pref.FieldDescriptor) pointerCoderFuncs {
}
}
-func makeMessageFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointerCoderFuncs {
+func makeMessageFieldCoder(fd protoreflect.FieldDescriptor, ft reflect.Type) pointerCoderFuncs {
if mi := getMessageInfo(ft); mi != nil {
funcs := pointerCoderFuncs{
size: sizeMessageInfo,
@@ -280,7 +280,7 @@ func consumeMessage(b []byte, m proto.Message, wtyp protowire.Type, opts unmarsh
if n < 0 {
return out, errDecode
}
- o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
+ o, err := opts.Options().UnmarshalState(protoiface.UnmarshalInput{
Buf: v,
Message: m.ProtoReflect(),
})
@@ -288,27 +288,27 @@ func consumeMessage(b []byte, m proto.Message, wtyp protowire.Type, opts unmarsh
return out, err
}
out.n = n
- out.initialized = o.Flags&piface.UnmarshalInitialized != 0
+ out.initialized = o.Flags&protoiface.UnmarshalInitialized != 0
return out, nil
}
-func sizeMessageValue(v pref.Value, tagsize int, opts marshalOptions) int {
+func sizeMessageValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
m := v.Message().Interface()
return sizeMessage(m, tagsize, opts)
}
-func appendMessageValue(b []byte, v pref.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
+func appendMessageValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
m := v.Message().Interface()
return appendMessage(b, m, wiretag, opts)
}
-func consumeMessageValue(b []byte, v pref.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (pref.Value, unmarshalOutput, error) {
+func consumeMessageValue(b []byte, v protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (protoreflect.Value, unmarshalOutput, error) {
m := v.Message().Interface()
out, err := consumeMessage(b, m, wtyp, opts)
return v, out, err
}
-func isInitMessageValue(v pref.Value) error {
+func isInitMessageValue(v protoreflect.Value) error {
m := v.Message().Interface()
return proto.CheckInitialized(m)
}
@@ -321,17 +321,17 @@ var coderMessageValue = valueCoderFuncs{
merge: mergeMessageValue,
}
-func sizeGroupValue(v pref.Value, tagsize int, opts marshalOptions) int {
+func sizeGroupValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
m := v.Message().Interface()
return sizeGroup(m, tagsize, opts)
}
-func appendGroupValue(b []byte, v pref.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
+func appendGroupValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
m := v.Message().Interface()
return appendGroup(b, m, wiretag, opts)
}
-func consumeGroupValue(b []byte, v pref.Value, num protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (pref.Value, unmarshalOutput, error) {
+func consumeGroupValue(b []byte, v protoreflect.Value, num protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (protoreflect.Value, unmarshalOutput, error) {
m := v.Message().Interface()
out, err := consumeGroup(b, m, num, wtyp, opts)
return v, out, err
@@ -345,7 +345,7 @@ var coderGroupValue = valueCoderFuncs{
merge: mergeMessageValue,
}
-func makeGroupFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointerCoderFuncs {
+func makeGroupFieldCoder(fd protoreflect.FieldDescriptor, ft reflect.Type) pointerCoderFuncs {
num := fd.Number()
if mi := getMessageInfo(ft); mi != nil {
funcs := pointerCoderFuncs{
@@ -424,7 +424,7 @@ func consumeGroup(b []byte, m proto.Message, num protowire.Number, wtyp protowir
if n < 0 {
return out, errDecode
}
- o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
+ o, err := opts.Options().UnmarshalState(protoiface.UnmarshalInput{
Buf: b,
Message: m.ProtoReflect(),
})
@@ -432,11 +432,11 @@ func consumeGroup(b []byte, m proto.Message, num protowire.Number, wtyp protowir
return out, err
}
out.n = n
- out.initialized = o.Flags&piface.UnmarshalInitialized != 0
+ out.initialized = o.Flags&protoiface.UnmarshalInitialized != 0
return out, nil
}
-func makeMessageSliceFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointerCoderFuncs {
+func makeMessageSliceFieldCoder(fd protoreflect.FieldDescriptor, ft reflect.Type) pointerCoderFuncs {
if mi := getMessageInfo(ft); mi != nil {
funcs := pointerCoderFuncs{
size: sizeMessageSliceInfo,
@@ -555,7 +555,7 @@ func consumeMessageSlice(b []byte, p pointer, goType reflect.Type, wtyp protowir
return out, errDecode
}
mp := reflect.New(goType.Elem())
- o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
+ o, err := opts.Options().UnmarshalState(protoiface.UnmarshalInput{
Buf: v,
Message: asMessage(mp).ProtoReflect(),
})
@@ -564,7 +564,7 @@ func consumeMessageSlice(b []byte, p pointer, goType reflect.Type, wtyp protowir
}
p.AppendPointerSlice(pointerOfValue(mp))
out.n = n
- out.initialized = o.Flags&piface.UnmarshalInitialized != 0
+ out.initialized = o.Flags&protoiface.UnmarshalInitialized != 0
return out, nil
}
@@ -581,7 +581,7 @@ func isInitMessageSlice(p pointer, goType reflect.Type) error {
// Slices of messages
-func sizeMessageSliceValue(listv pref.Value, tagsize int, opts marshalOptions) int {
+func sizeMessageSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) int {
list := listv.List()
n := 0
for i, llen := 0, list.Len(); i < llen; i++ {
@@ -591,7 +591,7 @@ func sizeMessageSliceValue(listv pref.Value, tagsize int, opts marshalOptions) i
return n
}
-func appendMessageSliceValue(b []byte, listv pref.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
+func appendMessageSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
list := listv.List()
mopts := opts.Options()
for i, llen := 0, list.Len(); i < llen; i++ {
@@ -608,30 +608,30 @@ func appendMessageSliceValue(b []byte, listv pref.Value, wiretag uint64, opts ma
return b, nil
}
-func consumeMessageSliceValue(b []byte, listv pref.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ pref.Value, out unmarshalOutput, err error) {
+func consumeMessageSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
list := listv.List()
if wtyp != protowire.BytesType {
- return pref.Value{}, out, errUnknown
+ return protoreflect.Value{}, out, errUnknown
}
v, n := protowire.ConsumeBytes(b)
if n < 0 {
- return pref.Value{}, out, errDecode
+ return protoreflect.Value{}, out, errDecode
}
m := list.NewElement()
- o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
+ o, err := opts.Options().UnmarshalState(protoiface.UnmarshalInput{
Buf: v,
Message: m.Message(),
})
if err != nil {
- return pref.Value{}, out, err
+ return protoreflect.Value{}, out, err
}
list.Append(m)
out.n = n
- out.initialized = o.Flags&piface.UnmarshalInitialized != 0
+ out.initialized = o.Flags&protoiface.UnmarshalInitialized != 0
return listv, out, nil
}
-func isInitMessageSliceValue(listv pref.Value) error {
+func isInitMessageSliceValue(listv protoreflect.Value) error {
list := listv.List()
for i, llen := 0, list.Len(); i < llen; i++ {
m := list.Get(i).Message().Interface()
@@ -650,7 +650,7 @@ var coderMessageSliceValue = valueCoderFuncs{
merge: mergeMessageListValue,
}
-func sizeGroupSliceValue(listv pref.Value, tagsize int, opts marshalOptions) int {
+func sizeGroupSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) int {
list := listv.List()
n := 0
for i, llen := 0, list.Len(); i < llen; i++ {
@@ -660,7 +660,7 @@ func sizeGroupSliceValue(listv pref.Value, tagsize int, opts marshalOptions) int
return n
}
-func appendGroupSliceValue(b []byte, listv pref.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
+func appendGroupSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
list := listv.List()
mopts := opts.Options()
for i, llen := 0, list.Len(); i < llen; i++ {
@@ -676,26 +676,26 @@ func appendGroupSliceValue(b []byte, listv pref.Value, wiretag uint64, opts mars
return b, nil
}
-func consumeGroupSliceValue(b []byte, listv pref.Value, num protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ pref.Value, out unmarshalOutput, err error) {
+func consumeGroupSliceValue(b []byte, listv protoreflect.Value, num protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
list := listv.List()
if wtyp != protowire.StartGroupType {
- return pref.Value{}, out, errUnknown
+ return protoreflect.Value{}, out, errUnknown
}
b, n := protowire.ConsumeGroup(num, b)
if n < 0 {
- return pref.Value{}, out, errDecode
+ return protoreflect.Value{}, out, errDecode
}
m := list.NewElement()
- o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
+ o, err := opts.Options().UnmarshalState(protoiface.UnmarshalInput{
Buf: b,
Message: m.Message(),
})
if err != nil {
- return pref.Value{}, out, err
+ return protoreflect.Value{}, out, err
}
list.Append(m)
out.n = n
- out.initialized = o.Flags&piface.UnmarshalInitialized != 0
+ out.initialized = o.Flags&protoiface.UnmarshalInitialized != 0
return listv, out, nil
}
@@ -707,7 +707,7 @@ var coderGroupSliceValue = valueCoderFuncs{
merge: mergeMessageListValue,
}
-func makeGroupSliceFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointerCoderFuncs {
+func makeGroupSliceFieldCoder(fd protoreflect.FieldDescriptor, ft reflect.Type) pointerCoderFuncs {
num := fd.Number()
if mi := getMessageInfo(ft); mi != nil {
funcs := pointerCoderFuncs{
@@ -772,7 +772,7 @@ func consumeGroupSlice(b []byte, p pointer, num protowire.Number, wtyp protowire
return out, errDecode
}
mp := reflect.New(goType.Elem())
- o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
+ o, err := opts.Options().UnmarshalState(protoiface.UnmarshalInput{
Buf: b,
Message: asMessage(mp).ProtoReflect(),
})
@@ -781,7 +781,7 @@ func consumeGroupSlice(b []byte, p pointer, num protowire.Number, wtyp protowire
}
p.AppendPointerSlice(pointerOfValue(mp))
out.n = n
- out.initialized = o.Flags&piface.UnmarshalInitialized != 0
+ out.initialized = o.Flags&protoiface.UnmarshalInitialized != 0
return out, nil
}
@@ -822,8 +822,8 @@ func consumeGroupSliceInfo(b []byte, p pointer, wtyp protowire.Type, f *coderFie
return out, nil
}
-func asMessage(v reflect.Value) pref.ProtoMessage {
- if m, ok := v.Interface().(pref.ProtoMessage); ok {
+func asMessage(v reflect.Value) protoreflect.ProtoMessage {
+ if m, ok := v.Interface().(protoreflect.ProtoMessage); ok {
return m
}
return legacyWrapMessage(v).Interface()
diff --git a/internal/impl/codec_map.go b/internal/impl/codec_map.go
index c1245fef..111b9d16 100644
--- a/internal/impl/codec_map.go
+++ b/internal/impl/codec_map.go
@@ -10,7 +10,7 @@ import (
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/genid"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
type mapInfo struct {
@@ -19,12 +19,12 @@ type mapInfo struct {
valWiretag uint64
keyFuncs valueCoderFuncs
valFuncs valueCoderFuncs
- keyZero pref.Value
- keyKind pref.Kind
+ keyZero protoreflect.Value
+ keyKind protoreflect.Kind
conv *mapConverter
}
-func encoderFuncsForMap(fd pref.FieldDescriptor, ft reflect.Type) (valueMessage *MessageInfo, funcs pointerCoderFuncs) {
+func encoderFuncsForMap(fd protoreflect.FieldDescriptor, ft reflect.Type) (valueMessage *MessageInfo, funcs pointerCoderFuncs) {
// TODO: Consider generating specialized map coders.
keyField := fd.MapKey()
valField := fd.MapValue()
@@ -44,7 +44,7 @@ func encoderFuncsForMap(fd pref.FieldDescriptor, ft reflect.Type) (valueMessage
keyKind: keyField.Kind(),
conv: conv,
}
- if valField.Kind() == pref.MessageKind {
+ if valField.Kind() == protoreflect.MessageKind {
valueMessage = getMessageInfo(ft.Elem())
}
@@ -68,9 +68,9 @@ func encoderFuncsForMap(fd pref.FieldDescriptor, ft reflect.Type) (valueMessage
},
}
switch valField.Kind() {
- case pref.MessageKind:
+ case protoreflect.MessageKind:
funcs.merge = mergeMapOfMessage
- case pref.BytesKind:
+ case protoreflect.BytesKind:
funcs.merge = mergeMapOfBytes
default:
funcs.merge = mergeMap
@@ -135,7 +135,7 @@ func consumeMap(b []byte, mapv reflect.Value, wtyp protowire.Type, mapi *mapInfo
err := errUnknown
switch num {
case genid.MapEntry_Key_field_number:
- var v pref.Value
+ var v protoreflect.Value
var o unmarshalOutput
v, o, err = mapi.keyFuncs.unmarshal(b, key, num, wtyp, opts)
if err != nil {
@@ -144,7 +144,7 @@ func consumeMap(b []byte, mapv reflect.Value, wtyp protowire.Type, mapi *mapInfo
key = v
n = o.n
case genid.MapEntry_Value_field_number:
- var v pref.Value
+ var v protoreflect.Value
var o unmarshalOutput
v, o, err = mapi.valFuncs.unmarshal(b, val, num, wtyp, opts)
if err != nil {
@@ -192,7 +192,7 @@ func consumeMapOfMessage(b []byte, mapv reflect.Value, wtyp protowire.Type, mapi
err := errUnknown
switch num {
case 1:
- var v pref.Value
+ var v protoreflect.Value
var o unmarshalOutput
v, o, err = mapi.keyFuncs.unmarshal(b, key, num, wtyp, opts)
if err != nil {
diff --git a/internal/impl/codec_message.go b/internal/impl/codec_message.go
index cd40527f..6b2fdbb7 100644
--- a/internal/impl/codec_message.go
+++ b/internal/impl/codec_message.go
@@ -12,15 +12,15 @@ import (
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/encoding/messageset"
"google.golang.org/protobuf/internal/order"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- piface "google.golang.org/protobuf/runtime/protoiface"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/runtime/protoiface"
)
// coderMessageInfo contains per-message information used by the fast-path functions.
// This is a different type from MessageInfo to keep MessageInfo as general-purpose as
// possible.
type coderMessageInfo struct {
- methods piface.Methods
+ methods protoiface.Methods
orderedCoderFields []*coderFieldInfo
denseCoderFields []*coderFieldInfo
@@ -38,13 +38,13 @@ type coderFieldInfo struct {
funcs pointerCoderFuncs // fast-path per-field functions
mi *MessageInfo // field's message
ft reflect.Type
- validation validationInfo // information used by message validation
- num pref.FieldNumber // field number
- offset offset // struct field offset
- wiretag uint64 // field tag (number + wire type)
- tagsize int // size of the varint-encoded tag
- isPointer bool // true if IsNil may be called on the struct field
- isRequired bool // true if field is required
+ validation validationInfo // information used by message validation
+ num protoreflect.FieldNumber // field number
+ offset offset // struct field offset
+ wiretag uint64 // field tag (number + wire type)
+ tagsize int // size of the varint-encoded tag
+ isPointer bool // true if IsNil may be called on the struct field
+ isRequired bool // true if field is required
}
func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
@@ -125,8 +125,8 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
funcs: funcs,
mi: childMessage,
validation: newFieldValidationInfo(mi, si, fd, ft),
- isPointer: fd.Cardinality() == pref.Repeated || fd.HasPresence(),
- isRequired: fd.Cardinality() == pref.Required,
+ isPointer: fd.Cardinality() == protoreflect.Repeated || fd.HasPresence(),
+ isRequired: fd.Cardinality() == protoreflect.Required,
}
mi.orderedCoderFields = append(mi.orderedCoderFields, cf)
mi.coderFields[cf.num] = cf
@@ -149,7 +149,7 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
return mi.orderedCoderFields[i].num < mi.orderedCoderFields[j].num
})
- var maxDense pref.FieldNumber
+ var maxDense protoreflect.FieldNumber
for _, cf := range mi.orderedCoderFields {
if cf.num >= 16 && cf.num >= 2*maxDense {
break
@@ -175,12 +175,12 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
mi.needsInitCheck = needsInitCheck(mi.Desc)
if mi.methods.Marshal == nil && mi.methods.Size == nil {
- mi.methods.Flags |= piface.SupportMarshalDeterministic
+ mi.methods.Flags |= protoiface.SupportMarshalDeterministic
mi.methods.Marshal = mi.marshal
mi.methods.Size = mi.size
}
if mi.methods.Unmarshal == nil {
- mi.methods.Flags |= piface.SupportUnmarshalDiscardUnknown
+ mi.methods.Flags |= protoiface.SupportUnmarshalDiscardUnknown
mi.methods.Unmarshal = mi.unmarshal
}
if mi.methods.CheckInitialized == nil {
diff --git a/internal/impl/codec_tables.go b/internal/impl/codec_tables.go
index e8997123..576dcf3a 100644
--- a/internal/impl/codec_tables.go
+++ b/internal/impl/codec_tables.go
@@ -10,7 +10,7 @@ import (
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/strs"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
// pointerCoderFuncs is a set of pointer encoding functions.
@@ -25,83 +25,83 @@ type pointerCoderFuncs struct {
// valueCoderFuncs is a set of protoreflect.Value encoding functions.
type valueCoderFuncs struct {
- size func(v pref.Value, tagsize int, opts marshalOptions) int
- marshal func(b []byte, v pref.Value, wiretag uint64, opts marshalOptions) ([]byte, error)
- unmarshal func(b []byte, v pref.Value, num protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (pref.Value, unmarshalOutput, error)
- isInit func(v pref.Value) error
- merge func(dst, src pref.Value, opts mergeOptions) pref.Value
+ size func(v protoreflect.Value, tagsize int, opts marshalOptions) int
+ marshal func(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error)
+ unmarshal func(b []byte, v protoreflect.Value, num protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (protoreflect.Value, unmarshalOutput, error)
+ isInit func(v protoreflect.Value) error
+ merge func(dst, src protoreflect.Value, opts mergeOptions) protoreflect.Value
}
// fieldCoder returns pointer functions for a field, used for operating on
// struct fields.
-func fieldCoder(fd pref.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointerCoderFuncs) {
+func fieldCoder(fd protoreflect.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointerCoderFuncs) {
switch {
case fd.IsMap():
return encoderFuncsForMap(fd, ft)
- case fd.Cardinality() == pref.Repeated && !fd.IsPacked():
+ case fd.Cardinality() == protoreflect.Repeated && !fd.IsPacked():
// Repeated fields (not packed).
if ft.Kind() != reflect.Slice {
break
}
ft := ft.Elem()
switch fd.Kind() {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
if ft.Kind() == reflect.Bool {
return nil, coderBoolSlice
}
- case pref.EnumKind:
+ case protoreflect.EnumKind:
if ft.Kind() == reflect.Int32 {
return nil, coderEnumSlice
}
- case pref.Int32Kind:
+ case protoreflect.Int32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderInt32Slice
}
- case pref.Sint32Kind:
+ case protoreflect.Sint32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderSint32Slice
}
- case pref.Uint32Kind:
+ case protoreflect.Uint32Kind:
if ft.Kind() == reflect.Uint32 {
return nil, coderUint32Slice
}
- case pref.Int64Kind:
+ case protoreflect.Int64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderInt64Slice
}
- case pref.Sint64Kind:
+ case protoreflect.Sint64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderSint64Slice
}
- case pref.Uint64Kind:
+ case protoreflect.Uint64Kind:
if ft.Kind() == reflect.Uint64 {
return nil, coderUint64Slice
}
- case pref.Sfixed32Kind:
+ case protoreflect.Sfixed32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderSfixed32Slice
}
- case pref.Fixed32Kind:
+ case protoreflect.Fixed32Kind:
if ft.Kind() == reflect.Uint32 {
return nil, coderFixed32Slice
}
- case pref.FloatKind:
+ case protoreflect.FloatKind:
if ft.Kind() == reflect.Float32 {
return nil, coderFloatSlice
}
- case pref.Sfixed64Kind:
+ case protoreflect.Sfixed64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderSfixed64Slice
}
- case pref.Fixed64Kind:
+ case protoreflect.Fixed64Kind:
if ft.Kind() == reflect.Uint64 {
return nil, coderFixed64Slice
}
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
if ft.Kind() == reflect.Float64 {
return nil, coderDoubleSlice
}
- case pref.StringKind:
+ case protoreflect.StringKind:
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
return nil, coderStringSliceValidateUTF8
}
@@ -114,19 +114,19 @@ func fieldCoder(fd pref.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointer
if ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8 {
return nil, coderBytesSlice
}
- case pref.BytesKind:
+ case protoreflect.BytesKind:
if ft.Kind() == reflect.String {
return nil, coderStringSlice
}
if ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8 {
return nil, coderBytesSlice
}
- case pref.MessageKind:
+ case protoreflect.MessageKind:
return getMessageInfo(ft), makeMessageSliceFieldCoder(fd, ft)
- case pref.GroupKind:
+ case protoreflect.GroupKind:
return getMessageInfo(ft), makeGroupSliceFieldCoder(fd, ft)
}
- case fd.Cardinality() == pref.Repeated && fd.IsPacked():
+ case fd.Cardinality() == protoreflect.Repeated && fd.IsPacked():
// Packed repeated fields.
//
// Only repeated fields of primitive numeric types
@@ -136,128 +136,128 @@ func fieldCoder(fd pref.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointer
}
ft := ft.Elem()
switch fd.Kind() {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
if ft.Kind() == reflect.Bool {
return nil, coderBoolPackedSlice
}
- case pref.EnumKind:
+ case protoreflect.EnumKind:
if ft.Kind() == reflect.Int32 {
return nil, coderEnumPackedSlice
}
- case pref.Int32Kind:
+ case protoreflect.Int32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderInt32PackedSlice
}
- case pref.Sint32Kind:
+ case protoreflect.Sint32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderSint32PackedSlice
}
- case pref.Uint32Kind:
+ case protoreflect.Uint32Kind:
if ft.Kind() == reflect.Uint32 {
return nil, coderUint32PackedSlice
}
- case pref.Int64Kind:
+ case protoreflect.Int64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderInt64PackedSlice
}
- case pref.Sint64Kind:
+ case protoreflect.Sint64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderSint64PackedSlice
}
- case pref.Uint64Kind:
+ case protoreflect.Uint64Kind:
if ft.Kind() == reflect.Uint64 {
return nil, coderUint64PackedSlice
}
- case pref.Sfixed32Kind:
+ case protoreflect.Sfixed32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderSfixed32PackedSlice
}
- case pref.Fixed32Kind:
+ case protoreflect.Fixed32Kind:
if ft.Kind() == reflect.Uint32 {
return nil, coderFixed32PackedSlice
}
- case pref.FloatKind:
+ case protoreflect.FloatKind:
if ft.Kind() == reflect.Float32 {
return nil, coderFloatPackedSlice
}
- case pref.Sfixed64Kind:
+ case protoreflect.Sfixed64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderSfixed64PackedSlice
}
- case pref.Fixed64Kind:
+ case protoreflect.Fixed64Kind:
if ft.Kind() == reflect.Uint64 {
return nil, coderFixed64PackedSlice
}
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
if ft.Kind() == reflect.Float64 {
return nil, coderDoublePackedSlice
}
}
- case fd.Kind() == pref.MessageKind:
+ case fd.Kind() == protoreflect.MessageKind:
return getMessageInfo(ft), makeMessageFieldCoder(fd, ft)
- case fd.Kind() == pref.GroupKind:
+ case fd.Kind() == protoreflect.GroupKind:
return getMessageInfo(ft), makeGroupFieldCoder(fd, ft)
- case fd.Syntax() == pref.Proto3 && fd.ContainingOneof() == nil:
+ case fd.Syntax() == protoreflect.Proto3 && fd.ContainingOneof() == nil:
// Populated oneof fields always encode even if set to the zero value,
// which normally are not encoded in proto3.
switch fd.Kind() {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
if ft.Kind() == reflect.Bool {
return nil, coderBoolNoZero
}
- case pref.EnumKind:
+ case protoreflect.EnumKind:
if ft.Kind() == reflect.Int32 {
return nil, coderEnumNoZero
}
- case pref.Int32Kind:
+ case protoreflect.Int32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderInt32NoZero
}
- case pref.Sint32Kind:
+ case protoreflect.Sint32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderSint32NoZero
}
- case pref.Uint32Kind:
+ case protoreflect.Uint32Kind:
if ft.Kind() == reflect.Uint32 {
return nil, coderUint32NoZero
}
- case pref.Int64Kind:
+ case protoreflect.Int64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderInt64NoZero
}
- case pref.Sint64Kind:
+ case protoreflect.Sint64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderSint64NoZero
}
- case pref.Uint64Kind:
+ case protoreflect.Uint64Kind:
if ft.Kind() == reflect.Uint64 {
return nil, coderUint64NoZero
}
- case pref.Sfixed32Kind:
+ case protoreflect.Sfixed32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderSfixed32NoZero
}
- case pref.Fixed32Kind:
+ case protoreflect.Fixed32Kind:
if ft.Kind() == reflect.Uint32 {
return nil, coderFixed32NoZero
}
- case pref.FloatKind:
+ case protoreflect.FloatKind:
if ft.Kind() == reflect.Float32 {
return nil, coderFloatNoZero
}
- case pref.Sfixed64Kind:
+ case protoreflect.Sfixed64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderSfixed64NoZero
}
- case pref.Fixed64Kind:
+ case protoreflect.Fixed64Kind:
if ft.Kind() == reflect.Uint64 {
return nil, coderFixed64NoZero
}
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
if ft.Kind() == reflect.Float64 {
return nil, coderDoubleNoZero
}
- case pref.StringKind:
+ case protoreflect.StringKind:
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
return nil, coderStringNoZeroValidateUTF8
}
@@ -270,7 +270,7 @@ func fieldCoder(fd pref.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointer
if ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8 {
return nil, coderBytesNoZero
}
- case pref.BytesKind:
+ case protoreflect.BytesKind:
if ft.Kind() == reflect.String {
return nil, coderStringNoZero
}
@@ -281,133 +281,133 @@ func fieldCoder(fd pref.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointer
case ft.Kind() == reflect.Ptr:
ft := ft.Elem()
switch fd.Kind() {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
if ft.Kind() == reflect.Bool {
return nil, coderBoolPtr
}
- case pref.EnumKind:
+ case protoreflect.EnumKind:
if ft.Kind() == reflect.Int32 {
return nil, coderEnumPtr
}
- case pref.Int32Kind:
+ case protoreflect.Int32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderInt32Ptr
}
- case pref.Sint32Kind:
+ case protoreflect.Sint32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderSint32Ptr
}
- case pref.Uint32Kind:
+ case protoreflect.Uint32Kind:
if ft.Kind() == reflect.Uint32 {
return nil, coderUint32Ptr
}
- case pref.Int64Kind:
+ case protoreflect.Int64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderInt64Ptr
}
- case pref.Sint64Kind:
+ case protoreflect.Sint64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderSint64Ptr
}
- case pref.Uint64Kind:
+ case protoreflect.Uint64Kind:
if ft.Kind() == reflect.Uint64 {
return nil, coderUint64Ptr
}
- case pref.Sfixed32Kind:
+ case protoreflect.Sfixed32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderSfixed32Ptr
}
- case pref.Fixed32Kind:
+ case protoreflect.Fixed32Kind:
if ft.Kind() == reflect.Uint32 {
return nil, coderFixed32Ptr
}
- case pref.FloatKind:
+ case protoreflect.FloatKind:
if ft.Kind() == reflect.Float32 {
return nil, coderFloatPtr
}
- case pref.Sfixed64Kind:
+ case protoreflect.Sfixed64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderSfixed64Ptr
}
- case pref.Fixed64Kind:
+ case protoreflect.Fixed64Kind:
if ft.Kind() == reflect.Uint64 {
return nil, coderFixed64Ptr
}
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
if ft.Kind() == reflect.Float64 {
return nil, coderDoublePtr
}
- case pref.StringKind:
+ case protoreflect.StringKind:
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
return nil, coderStringPtrValidateUTF8
}
if ft.Kind() == reflect.String {
return nil, coderStringPtr
}
- case pref.BytesKind:
+ case protoreflect.BytesKind:
if ft.Kind() == reflect.String {
return nil, coderStringPtr
}
}
default:
switch fd.Kind() {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
if ft.Kind() == reflect.Bool {
return nil, coderBool
}
- case pref.EnumKind:
+ case protoreflect.EnumKind:
if ft.Kind() == reflect.Int32 {
return nil, coderEnum
}
- case pref.Int32Kind:
+ case protoreflect.Int32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderInt32
}
- case pref.Sint32Kind:
+ case protoreflect.Sint32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderSint32
}
- case pref.Uint32Kind:
+ case protoreflect.Uint32Kind:
if ft.Kind() == reflect.Uint32 {
return nil, coderUint32
}
- case pref.Int64Kind:
+ case protoreflect.Int64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderInt64
}
- case pref.Sint64Kind:
+ case protoreflect.Sint64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderSint64
}
- case pref.Uint64Kind:
+ case protoreflect.Uint64Kind:
if ft.Kind() == reflect.Uint64 {
return nil, coderUint64
}
- case pref.Sfixed32Kind:
+ case protoreflect.Sfixed32Kind:
if ft.Kind() == reflect.Int32 {
return nil, coderSfixed32
}
- case pref.Fixed32Kind:
+ case protoreflect.Fixed32Kind:
if ft.Kind() == reflect.Uint32 {
return nil, coderFixed32
}
- case pref.FloatKind:
+ case protoreflect.FloatKind:
if ft.Kind() == reflect.Float32 {
return nil, coderFloat
}
- case pref.Sfixed64Kind:
+ case protoreflect.Sfixed64Kind:
if ft.Kind() == reflect.Int64 {
return nil, coderSfixed64
}
- case pref.Fixed64Kind:
+ case protoreflect.Fixed64Kind:
if ft.Kind() == reflect.Uint64 {
return nil, coderFixed64
}
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
if ft.Kind() == reflect.Float64 {
return nil, coderDouble
}
- case pref.StringKind:
+ case protoreflect.StringKind:
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
return nil, coderStringValidateUTF8
}
@@ -420,7 +420,7 @@ func fieldCoder(fd pref.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointer
if ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8 {
return nil, coderBytes
}
- case pref.BytesKind:
+ case protoreflect.BytesKind:
if ft.Kind() == reflect.String {
return nil, coderString
}
@@ -434,122 +434,122 @@ func fieldCoder(fd pref.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointer
// encoderFuncsForValue returns value functions for a field, used for
// extension values and map encoding.
-func encoderFuncsForValue(fd pref.FieldDescriptor) valueCoderFuncs {
+func encoderFuncsForValue(fd protoreflect.FieldDescriptor) valueCoderFuncs {
switch {
- case fd.Cardinality() == pref.Repeated && !fd.IsPacked():
+ case fd.Cardinality() == protoreflect.Repeated && !fd.IsPacked():
switch fd.Kind() {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
return coderBoolSliceValue
- case pref.EnumKind:
+ case protoreflect.EnumKind:
return coderEnumSliceValue
- case pref.Int32Kind:
+ case protoreflect.Int32Kind:
return coderInt32SliceValue
- case pref.Sint32Kind:
+ case protoreflect.Sint32Kind:
return coderSint32SliceValue
- case pref.Uint32Kind:
+ case protoreflect.Uint32Kind:
return coderUint32SliceValue
- case pref.Int64Kind:
+ case protoreflect.Int64Kind:
return coderInt64SliceValue
- case pref.Sint64Kind:
+ case protoreflect.Sint64Kind:
return coderSint64SliceValue
- case pref.Uint64Kind:
+ case protoreflect.Uint64Kind:
return coderUint64SliceValue
- case pref.Sfixed32Kind:
+ case protoreflect.Sfixed32Kind:
return coderSfixed32SliceValue
- case pref.Fixed32Kind:
+ case protoreflect.Fixed32Kind:
return coderFixed32SliceValue
- case pref.FloatKind:
+ case protoreflect.FloatKind:
return coderFloatSliceValue
- case pref.Sfixed64Kind:
+ case protoreflect.Sfixed64Kind:
return coderSfixed64SliceValue
- case pref.Fixed64Kind:
+ case protoreflect.Fixed64Kind:
return coderFixed64SliceValue
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
return coderDoubleSliceValue
- case pref.StringKind:
+ case protoreflect.StringKind:
// We don't have a UTF-8 validating coder for repeated string fields.
// Value coders are used for extensions and maps.
// Extensions are never proto3, and maps never contain lists.
return coderStringSliceValue
- case pref.BytesKind:
+ case protoreflect.BytesKind:
return coderBytesSliceValue
- case pref.MessageKind:
+ case protoreflect.MessageKind:
return coderMessageSliceValue
- case pref.GroupKind:
+ case protoreflect.GroupKind:
return coderGroupSliceValue
}
- case fd.Cardinality() == pref.Repeated && fd.IsPacked():
+ case fd.Cardinality() == protoreflect.Repeated && fd.IsPacked():
switch fd.Kind() {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
return coderBoolPackedSliceValue
- case pref.EnumKind:
+ case protoreflect.EnumKind:
return coderEnumPackedSliceValue
- case pref.Int32Kind:
+ case protoreflect.Int32Kind:
return coderInt32PackedSliceValue
- case pref.Sint32Kind:
+ case protoreflect.Sint32Kind:
return coderSint32PackedSliceValue
- case pref.Uint32Kind:
+ case protoreflect.Uint32Kind:
return coderUint32PackedSliceValue
- case pref.Int64Kind:
+ case protoreflect.Int64Kind:
return coderInt64PackedSliceValue
- case pref.Sint64Kind:
+ case protoreflect.Sint64Kind:
return coderSint64PackedSliceValue
- case pref.Uint64Kind:
+ case protoreflect.Uint64Kind:
return coderUint64PackedSliceValue
- case pref.Sfixed32Kind:
+ case protoreflect.Sfixed32Kind:
return coderSfixed32PackedSliceValue
- case pref.Fixed32Kind:
+ case protoreflect.Fixed32Kind:
return coderFixed32PackedSliceValue
- case pref.FloatKind:
+ case protoreflect.FloatKind:
return coderFloatPackedSliceValue
- case pref.Sfixed64Kind:
+ case protoreflect.Sfixed64Kind:
return coderSfixed64PackedSliceValue
- case pref.Fixed64Kind:
+ case protoreflect.Fixed64Kind:
return coderFixed64PackedSliceValue
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
return coderDoublePackedSliceValue
}
default:
switch fd.Kind() {
default:
- case pref.BoolKind:
+ case protoreflect.BoolKind:
return coderBoolValue
- case pref.EnumKind:
+ case protoreflect.EnumKind:
return coderEnumValue
- case pref.Int32Kind:
+ case protoreflect.Int32Kind:
return coderInt32Value
- case pref.Sint32Kind:
+ case protoreflect.Sint32Kind:
return coderSint32Value
- case pref.Uint32Kind:
+ case protoreflect.Uint32Kind:
return coderUint32Value
- case pref.Int64Kind:
+ case protoreflect.Int64Kind:
return coderInt64Value
- case pref.Sint64Kind:
+ case protoreflect.Sint64Kind:
return coderSint64Value
- case pref.Uint64Kind:
+ case protoreflect.Uint64Kind:
return coderUint64Value
- case pref.Sfixed32Kind:
+ case protoreflect.Sfixed32Kind:
return coderSfixed32Value
- case pref.Fixed32Kind:
+ case protoreflect.Fixed32Kind:
return coderFixed32Value
- case pref.FloatKind:
+ case protoreflect.FloatKind:
return coderFloatValue
- case pref.Sfixed64Kind:
+ case protoreflect.Sfixed64Kind:
return coderSfixed64Value
- case pref.Fixed64Kind:
+ case protoreflect.Fixed64Kind:
return coderFixed64Value
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
return coderDoubleValue
- case pref.StringKind:
+ case protoreflect.StringKind:
if strs.EnforceUTF8(fd) {
return coderStringValueValidateUTF8
}
return coderStringValue
- case pref.BytesKind:
+ case protoreflect.BytesKind:
return coderBytesValue
- case pref.MessageKind:
+ case protoreflect.MessageKind:
return coderMessageValue
- case pref.GroupKind:
+ case protoreflect.GroupKind:
return coderGroupValue
}
}
diff --git a/internal/impl/convert.go b/internal/impl/convert.go
index acd61bb5..11a6128b 100644
--- a/internal/impl/convert.go
+++ b/internal/impl/convert.go
@@ -8,7 +8,7 @@ import (
"fmt"
"reflect"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
// unwrapper unwraps the value to the underlying value.
@@ -20,13 +20,13 @@ type unwrapper interface {
// A Converter coverts to/from Go reflect.Value types and protobuf protoreflect.Value types.
type Converter interface {
// PBValueOf converts a reflect.Value to a protoreflect.Value.
- PBValueOf(reflect.Value) pref.Value
+ PBValueOf(reflect.Value) protoreflect.Value
// GoValueOf converts a protoreflect.Value to a reflect.Value.
- GoValueOf(pref.Value) reflect.Value
+ GoValueOf(protoreflect.Value) reflect.Value
// IsValidPB returns whether a protoreflect.Value is compatible with this type.
- IsValidPB(pref.Value) bool
+ IsValidPB(protoreflect.Value) bool
// IsValidGo returns whether a reflect.Value is compatible with this type.
IsValidGo(reflect.Value) bool
@@ -34,12 +34,12 @@ type Converter interface {
// New returns a new field value.
// For scalars, it returns the default value of the field.
// For composite types, it returns a new mutable value.
- New() pref.Value
+ New() protoreflect.Value
// Zero returns a new field value.
// For scalars, it returns the default value of the field.
// For composite types, it returns an immutable, empty value.
- Zero() pref.Value
+ Zero() protoreflect.Value
}
// NewConverter matches a Go type with a protobuf field and returns a Converter
@@ -50,7 +50,7 @@ type Converter interface {
// This matcher deliberately supports a wider range of Go types than what
// protoc-gen-go historically generated to be able to automatically wrap some
// v1 messages generated by other forks of protoc-gen-go.
-func NewConverter(t reflect.Type, fd pref.FieldDescriptor) Converter {
+func NewConverter(t reflect.Type, fd protoreflect.FieldDescriptor) Converter {
switch {
case fd.IsList():
return newListConverter(t, fd)
@@ -76,68 +76,68 @@ var (
)
var (
- boolZero = pref.ValueOfBool(false)
- int32Zero = pref.ValueOfInt32(0)
- int64Zero = pref.ValueOfInt64(0)
- uint32Zero = pref.ValueOfUint32(0)
- uint64Zero = pref.ValueOfUint64(0)
- float32Zero = pref.ValueOfFloat32(0)
- float64Zero = pref.ValueOfFloat64(0)
- stringZero = pref.ValueOfString("")
- bytesZero = pref.ValueOfBytes(nil)
+ boolZero = protoreflect.ValueOfBool(false)
+ int32Zero = protoreflect.ValueOfInt32(0)
+ int64Zero = protoreflect.ValueOfInt64(0)
+ uint32Zero = protoreflect.ValueOfUint32(0)
+ uint64Zero = protoreflect.ValueOfUint64(0)
+ float32Zero = protoreflect.ValueOfFloat32(0)
+ float64Zero = protoreflect.ValueOfFloat64(0)
+ stringZero = protoreflect.ValueOfString("")
+ bytesZero = protoreflect.ValueOfBytes(nil)
)
-func newSingularConverter(t reflect.Type, fd pref.FieldDescriptor) Converter {
- defVal := func(fd pref.FieldDescriptor, zero pref.Value) pref.Value {
- if fd.Cardinality() == pref.Repeated {
+func newSingularConverter(t reflect.Type, fd protoreflect.FieldDescriptor) Converter {
+ defVal := func(fd protoreflect.FieldDescriptor, zero protoreflect.Value) protoreflect.Value {
+ if fd.Cardinality() == protoreflect.Repeated {
// Default isn't defined for repeated fields.
return zero
}
return fd.Default()
}
switch fd.Kind() {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
if t.Kind() == reflect.Bool {
return &boolConverter{t, defVal(fd, boolZero)}
}
- case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
if t.Kind() == reflect.Int32 {
return &int32Converter{t, defVal(fd, int32Zero)}
}
- case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
+ case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
if t.Kind() == reflect.Int64 {
return &int64Converter{t, defVal(fd, int64Zero)}
}
- case pref.Uint32Kind, pref.Fixed32Kind:
+ case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
if t.Kind() == reflect.Uint32 {
return &uint32Converter{t, defVal(fd, uint32Zero)}
}
- case pref.Uint64Kind, pref.Fixed64Kind:
+ case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
if t.Kind() == reflect.Uint64 {
return &uint64Converter{t, defVal(fd, uint64Zero)}
}
- case pref.FloatKind:
+ case protoreflect.FloatKind:
if t.Kind() == reflect.Float32 {
return &float32Converter{t, defVal(fd, float32Zero)}
}
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
if t.Kind() == reflect.Float64 {
return &float64Converter{t, defVal(fd, float64Zero)}
}
- case pref.StringKind:
+ case protoreflect.StringKind:
if t.Kind() == reflect.String || (t.Kind() == reflect.Slice && t.Elem() == byteType) {
return &stringConverter{t, defVal(fd, stringZero)}
}
- case pref.BytesKind:
+ case protoreflect.BytesKind:
if t.Kind() == reflect.String || (t.Kind() == reflect.Slice && t.Elem() == byteType) {
return &bytesConverter{t, defVal(fd, bytesZero)}
}
- case pref.EnumKind:
+ case protoreflect.EnumKind:
// Handle enums, which must be a named int32 type.
if t.Kind() == reflect.Int32 {
return newEnumConverter(t, fd)
}
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
return newMessageConverter(t)
}
panic(fmt.Sprintf("invalid Go type %v for field %v", t, fd.FullName()))
@@ -145,184 +145,184 @@ func newSingularConverter(t reflect.Type, fd pref.FieldDescriptor) Converter {
type boolConverter struct {
goType reflect.Type
- def pref.Value
+ def protoreflect.Value
}
-func (c *boolConverter) PBValueOf(v reflect.Value) pref.Value {
+func (c *boolConverter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
- return pref.ValueOfBool(v.Bool())
+ return protoreflect.ValueOfBool(v.Bool())
}
-func (c *boolConverter) GoValueOf(v pref.Value) reflect.Value {
+func (c *boolConverter) GoValueOf(v protoreflect.Value) reflect.Value {
return reflect.ValueOf(v.Bool()).Convert(c.goType)
}
-func (c *boolConverter) IsValidPB(v pref.Value) bool {
+func (c *boolConverter) IsValidPB(v protoreflect.Value) bool {
_, ok := v.Interface().(bool)
return ok
}
func (c *boolConverter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *boolConverter) New() pref.Value { return c.def }
-func (c *boolConverter) Zero() pref.Value { return c.def }
+func (c *boolConverter) New() protoreflect.Value { return c.def }
+func (c *boolConverter) Zero() protoreflect.Value { return c.def }
type int32Converter struct {
goType reflect.Type
- def pref.Value
+ def protoreflect.Value
}
-func (c *int32Converter) PBValueOf(v reflect.Value) pref.Value {
+func (c *int32Converter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
- return pref.ValueOfInt32(int32(v.Int()))
+ return protoreflect.ValueOfInt32(int32(v.Int()))
}
-func (c *int32Converter) GoValueOf(v pref.Value) reflect.Value {
+func (c *int32Converter) GoValueOf(v protoreflect.Value) reflect.Value {
return reflect.ValueOf(int32(v.Int())).Convert(c.goType)
}
-func (c *int32Converter) IsValidPB(v pref.Value) bool {
+func (c *int32Converter) IsValidPB(v protoreflect.Value) bool {
_, ok := v.Interface().(int32)
return ok
}
func (c *int32Converter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *int32Converter) New() pref.Value { return c.def }
-func (c *int32Converter) Zero() pref.Value { return c.def }
+func (c *int32Converter) New() protoreflect.Value { return c.def }
+func (c *int32Converter) Zero() protoreflect.Value { return c.def }
type int64Converter struct {
goType reflect.Type
- def pref.Value
+ def protoreflect.Value
}
-func (c *int64Converter) PBValueOf(v reflect.Value) pref.Value {
+func (c *int64Converter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
- return pref.ValueOfInt64(int64(v.Int()))
+ return protoreflect.ValueOfInt64(int64(v.Int()))
}
-func (c *int64Converter) GoValueOf(v pref.Value) reflect.Value {
+func (c *int64Converter) GoValueOf(v protoreflect.Value) reflect.Value {
return reflect.ValueOf(int64(v.Int())).Convert(c.goType)
}
-func (c *int64Converter) IsValidPB(v pref.Value) bool {
+func (c *int64Converter) IsValidPB(v protoreflect.Value) bool {
_, ok := v.Interface().(int64)
return ok
}
func (c *int64Converter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *int64Converter) New() pref.Value { return c.def }
-func (c *int64Converter) Zero() pref.Value { return c.def }
+func (c *int64Converter) New() protoreflect.Value { return c.def }
+func (c *int64Converter) Zero() protoreflect.Value { return c.def }
type uint32Converter struct {
goType reflect.Type
- def pref.Value
+ def protoreflect.Value
}
-func (c *uint32Converter) PBValueOf(v reflect.Value) pref.Value {
+func (c *uint32Converter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
- return pref.ValueOfUint32(uint32(v.Uint()))
+ return protoreflect.ValueOfUint32(uint32(v.Uint()))
}
-func (c *uint32Converter) GoValueOf(v pref.Value) reflect.Value {
+func (c *uint32Converter) GoValueOf(v protoreflect.Value) reflect.Value {
return reflect.ValueOf(uint32(v.Uint())).Convert(c.goType)
}
-func (c *uint32Converter) IsValidPB(v pref.Value) bool {
+func (c *uint32Converter) IsValidPB(v protoreflect.Value) bool {
_, ok := v.Interface().(uint32)
return ok
}
func (c *uint32Converter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *uint32Converter) New() pref.Value { return c.def }
-func (c *uint32Converter) Zero() pref.Value { return c.def }
+func (c *uint32Converter) New() protoreflect.Value { return c.def }
+func (c *uint32Converter) Zero() protoreflect.Value { return c.def }
type uint64Converter struct {
goType reflect.Type
- def pref.Value
+ def protoreflect.Value
}
-func (c *uint64Converter) PBValueOf(v reflect.Value) pref.Value {
+func (c *uint64Converter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
- return pref.ValueOfUint64(uint64(v.Uint()))
+ return protoreflect.ValueOfUint64(uint64(v.Uint()))
}
-func (c *uint64Converter) GoValueOf(v pref.Value) reflect.Value {
+func (c *uint64Converter) GoValueOf(v protoreflect.Value) reflect.Value {
return reflect.ValueOf(uint64(v.Uint())).Convert(c.goType)
}
-func (c *uint64Converter) IsValidPB(v pref.Value) bool {
+func (c *uint64Converter) IsValidPB(v protoreflect.Value) bool {
_, ok := v.Interface().(uint64)
return ok
}
func (c *uint64Converter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *uint64Converter) New() pref.Value { return c.def }
-func (c *uint64Converter) Zero() pref.Value { return c.def }
+func (c *uint64Converter) New() protoreflect.Value { return c.def }
+func (c *uint64Converter) Zero() protoreflect.Value { return c.def }
type float32Converter struct {
goType reflect.Type
- def pref.Value
+ def protoreflect.Value
}
-func (c *float32Converter) PBValueOf(v reflect.Value) pref.Value {
+func (c *float32Converter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
- return pref.ValueOfFloat32(float32(v.Float()))
+ return protoreflect.ValueOfFloat32(float32(v.Float()))
}
-func (c *float32Converter) GoValueOf(v pref.Value) reflect.Value {
+func (c *float32Converter) GoValueOf(v protoreflect.Value) reflect.Value {
return reflect.ValueOf(float32(v.Float())).Convert(c.goType)
}
-func (c *float32Converter) IsValidPB(v pref.Value) bool {
+func (c *float32Converter) IsValidPB(v protoreflect.Value) bool {
_, ok := v.Interface().(float32)
return ok
}
func (c *float32Converter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *float32Converter) New() pref.Value { return c.def }
-func (c *float32Converter) Zero() pref.Value { return c.def }
+func (c *float32Converter) New() protoreflect.Value { return c.def }
+func (c *float32Converter) Zero() protoreflect.Value { return c.def }
type float64Converter struct {
goType reflect.Type
- def pref.Value
+ def protoreflect.Value
}
-func (c *float64Converter) PBValueOf(v reflect.Value) pref.Value {
+func (c *float64Converter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
- return pref.ValueOfFloat64(float64(v.Float()))
+ return protoreflect.ValueOfFloat64(float64(v.Float()))
}
-func (c *float64Converter) GoValueOf(v pref.Value) reflect.Value {
+func (c *float64Converter) GoValueOf(v protoreflect.Value) reflect.Value {
return reflect.ValueOf(float64(v.Float())).Convert(c.goType)
}
-func (c *float64Converter) IsValidPB(v pref.Value) bool {
+func (c *float64Converter) IsValidPB(v protoreflect.Value) bool {
_, ok := v.Interface().(float64)
return ok
}
func (c *float64Converter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *float64Converter) New() pref.Value { return c.def }
-func (c *float64Converter) Zero() pref.Value { return c.def }
+func (c *float64Converter) New() protoreflect.Value { return c.def }
+func (c *float64Converter) Zero() protoreflect.Value { return c.def }
type stringConverter struct {
goType reflect.Type
- def pref.Value
+ def protoreflect.Value
}
-func (c *stringConverter) PBValueOf(v reflect.Value) pref.Value {
+func (c *stringConverter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
- return pref.ValueOfString(v.Convert(stringType).String())
+ return protoreflect.ValueOfString(v.Convert(stringType).String())
}
-func (c *stringConverter) GoValueOf(v pref.Value) reflect.Value {
+func (c *stringConverter) GoValueOf(v protoreflect.Value) reflect.Value {
// pref.Value.String never panics, so we go through an interface
// conversion here to check the type.
s := v.Interface().(string)
@@ -331,71 +331,71 @@ func (c *stringConverter) GoValueOf(v pref.Value) reflect.Value {
}
return reflect.ValueOf(s).Convert(c.goType)
}
-func (c *stringConverter) IsValidPB(v pref.Value) bool {
+func (c *stringConverter) IsValidPB(v protoreflect.Value) bool {
_, ok := v.Interface().(string)
return ok
}
func (c *stringConverter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *stringConverter) New() pref.Value { return c.def }
-func (c *stringConverter) Zero() pref.Value { return c.def }
+func (c *stringConverter) New() protoreflect.Value { return c.def }
+func (c *stringConverter) Zero() protoreflect.Value { return c.def }
type bytesConverter struct {
goType reflect.Type
- def pref.Value
+ def protoreflect.Value
}
-func (c *bytesConverter) PBValueOf(v reflect.Value) pref.Value {
+func (c *bytesConverter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
if c.goType.Kind() == reflect.String && v.Len() == 0 {
- return pref.ValueOfBytes(nil) // ensure empty string is []byte(nil)
+ return protoreflect.ValueOfBytes(nil) // ensure empty string is []byte(nil)
}
- return pref.ValueOfBytes(v.Convert(bytesType).Bytes())
+ return protoreflect.ValueOfBytes(v.Convert(bytesType).Bytes())
}
-func (c *bytesConverter) GoValueOf(v pref.Value) reflect.Value {
+func (c *bytesConverter) GoValueOf(v protoreflect.Value) reflect.Value {
return reflect.ValueOf(v.Bytes()).Convert(c.goType)
}
-func (c *bytesConverter) IsValidPB(v pref.Value) bool {
+func (c *bytesConverter) IsValidPB(v protoreflect.Value) bool {
_, ok := v.Interface().([]byte)
return ok
}
func (c *bytesConverter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *bytesConverter) New() pref.Value { return c.def }
-func (c *bytesConverter) Zero() pref.Value { return c.def }
+func (c *bytesConverter) New() protoreflect.Value { return c.def }
+func (c *bytesConverter) Zero() protoreflect.Value { return c.def }
type enumConverter struct {
goType reflect.Type
- def pref.Value
+ def protoreflect.Value
}
-func newEnumConverter(goType reflect.Type, fd pref.FieldDescriptor) Converter {
- var def pref.Value
- if fd.Cardinality() == pref.Repeated {
- def = pref.ValueOfEnum(fd.Enum().Values().Get(0).Number())
+func newEnumConverter(goType reflect.Type, fd protoreflect.FieldDescriptor) Converter {
+ var def protoreflect.Value
+ if fd.Cardinality() == protoreflect.Repeated {
+ def = protoreflect.ValueOfEnum(fd.Enum().Values().Get(0).Number())
} else {
def = fd.Default()
}
return &enumConverter{goType, def}
}
-func (c *enumConverter) PBValueOf(v reflect.Value) pref.Value {
+func (c *enumConverter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
- return pref.ValueOfEnum(pref.EnumNumber(v.Int()))
+ return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v.Int()))
}
-func (c *enumConverter) GoValueOf(v pref.Value) reflect.Value {
+func (c *enumConverter) GoValueOf(v protoreflect.Value) reflect.Value {
return reflect.ValueOf(v.Enum()).Convert(c.goType)
}
-func (c *enumConverter) IsValidPB(v pref.Value) bool {
- _, ok := v.Interface().(pref.EnumNumber)
+func (c *enumConverter) IsValidPB(v protoreflect.Value) bool {
+ _, ok := v.Interface().(protoreflect.EnumNumber)
return ok
}
@@ -403,11 +403,11 @@ func (c *enumConverter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *enumConverter) New() pref.Value {
+func (c *enumConverter) New() protoreflect.Value {
return c.def
}
-func (c *enumConverter) Zero() pref.Value {
+func (c *enumConverter) Zero() protoreflect.Value {
return c.def
}
@@ -419,7 +419,7 @@ func newMessageConverter(goType reflect.Type) Converter {
return &messageConverter{goType}
}
-func (c *messageConverter) PBValueOf(v reflect.Value) pref.Value {
+func (c *messageConverter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
@@ -430,13 +430,13 @@ func (c *messageConverter) PBValueOf(v reflect.Value) pref.Value {
v = reflect.Zero(reflect.PtrTo(v.Type()))
}
}
- if m, ok := v.Interface().(pref.ProtoMessage); ok {
- return pref.ValueOfMessage(m.ProtoReflect())
+ if m, ok := v.Interface().(protoreflect.ProtoMessage); ok {
+ return protoreflect.ValueOfMessage(m.ProtoReflect())
}
- return pref.ValueOfMessage(legacyWrapMessage(v))
+ return protoreflect.ValueOfMessage(legacyWrapMessage(v))
}
-func (c *messageConverter) GoValueOf(v pref.Value) reflect.Value {
+func (c *messageConverter) GoValueOf(v protoreflect.Value) reflect.Value {
m := v.Message()
var rv reflect.Value
if u, ok := m.(unwrapper); ok {
@@ -460,7 +460,7 @@ func (c *messageConverter) GoValueOf(v pref.Value) reflect.Value {
return rv
}
-func (c *messageConverter) IsValidPB(v pref.Value) bool {
+func (c *messageConverter) IsValidPB(v protoreflect.Value) bool {
m := v.Message()
var rv reflect.Value
if u, ok := m.(unwrapper); ok {
@@ -478,14 +478,14 @@ func (c *messageConverter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *messageConverter) New() pref.Value {
+func (c *messageConverter) New() protoreflect.Value {
if c.isNonPointer() {
return c.PBValueOf(reflect.New(c.goType).Elem())
}
return c.PBValueOf(reflect.New(c.goType.Elem()))
}
-func (c *messageConverter) Zero() pref.Value {
+func (c *messageConverter) Zero() protoreflect.Value {
return c.PBValueOf(reflect.Zero(c.goType))
}
diff --git a/internal/impl/convert_list.go b/internal/impl/convert_list.go
index 6fccab52..f8913651 100644
--- a/internal/impl/convert_list.go
+++ b/internal/impl/convert_list.go
@@ -8,10 +8,10 @@ import (
"fmt"
"reflect"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
-func newListConverter(t reflect.Type, fd pref.FieldDescriptor) Converter {
+func newListConverter(t reflect.Type, fd protoreflect.FieldDescriptor) Converter {
switch {
case t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Slice:
return &listPtrConverter{t, newSingularConverter(t.Elem().Elem(), fd)}
@@ -26,16 +26,16 @@ type listConverter struct {
c Converter
}
-func (c *listConverter) PBValueOf(v reflect.Value) pref.Value {
+func (c *listConverter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
pv := reflect.New(c.goType)
pv.Elem().Set(v)
- return pref.ValueOfList(&listReflect{pv, c.c})
+ return protoreflect.ValueOfList(&listReflect{pv, c.c})
}
-func (c *listConverter) GoValueOf(v pref.Value) reflect.Value {
+func (c *listConverter) GoValueOf(v protoreflect.Value) reflect.Value {
rv := v.List().(*listReflect).v
if rv.IsNil() {
return reflect.Zero(c.goType)
@@ -43,7 +43,7 @@ func (c *listConverter) GoValueOf(v pref.Value) reflect.Value {
return rv.Elem()
}
-func (c *listConverter) IsValidPB(v pref.Value) bool {
+func (c *listConverter) IsValidPB(v protoreflect.Value) bool {
list, ok := v.Interface().(*listReflect)
if !ok {
return false
@@ -55,12 +55,12 @@ func (c *listConverter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *listConverter) New() pref.Value {
- return pref.ValueOfList(&listReflect{reflect.New(c.goType), c.c})
+func (c *listConverter) New() protoreflect.Value {
+ return protoreflect.ValueOfList(&listReflect{reflect.New(c.goType), c.c})
}
-func (c *listConverter) Zero() pref.Value {
- return pref.ValueOfList(&listReflect{reflect.Zero(reflect.PtrTo(c.goType)), c.c})
+func (c *listConverter) Zero() protoreflect.Value {
+ return protoreflect.ValueOfList(&listReflect{reflect.Zero(reflect.PtrTo(c.goType)), c.c})
}
type listPtrConverter struct {
@@ -68,18 +68,18 @@ type listPtrConverter struct {
c Converter
}
-func (c *listPtrConverter) PBValueOf(v reflect.Value) pref.Value {
+func (c *listPtrConverter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
- return pref.ValueOfList(&listReflect{v, c.c})
+ return protoreflect.ValueOfList(&listReflect{v, c.c})
}
-func (c *listPtrConverter) GoValueOf(v pref.Value) reflect.Value {
+func (c *listPtrConverter) GoValueOf(v protoreflect.Value) reflect.Value {
return v.List().(*listReflect).v
}
-func (c *listPtrConverter) IsValidPB(v pref.Value) bool {
+func (c *listPtrConverter) IsValidPB(v protoreflect.Value) bool {
list, ok := v.Interface().(*listReflect)
if !ok {
return false
@@ -91,11 +91,11 @@ func (c *listPtrConverter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *listPtrConverter) New() pref.Value {
+func (c *listPtrConverter) New() protoreflect.Value {
return c.PBValueOf(reflect.New(c.goType.Elem()))
}
-func (c *listPtrConverter) Zero() pref.Value {
+func (c *listPtrConverter) Zero() protoreflect.Value {
return c.PBValueOf(reflect.Zero(c.goType))
}
@@ -110,16 +110,16 @@ func (ls *listReflect) Len() int {
}
return ls.v.Elem().Len()
}
-func (ls *listReflect) Get(i int) pref.Value {
+func (ls *listReflect) Get(i int) protoreflect.Value {
return ls.conv.PBValueOf(ls.v.Elem().Index(i))
}
-func (ls *listReflect) Set(i int, v pref.Value) {
+func (ls *listReflect) Set(i int, v protoreflect.Value) {
ls.v.Elem().Index(i).Set(ls.conv.GoValueOf(v))
}
-func (ls *listReflect) Append(v pref.Value) {
+func (ls *listReflect) Append(v protoreflect.Value) {
ls.v.Elem().Set(reflect.Append(ls.v.Elem(), ls.conv.GoValueOf(v)))
}
-func (ls *listReflect) AppendMutable() pref.Value {
+func (ls *listReflect) AppendMutable() protoreflect.Value {
if _, ok := ls.conv.(*messageConverter); !ok {
panic("invalid AppendMutable on list with non-message type")
}
@@ -130,7 +130,7 @@ func (ls *listReflect) AppendMutable() pref.Value {
func (ls *listReflect) Truncate(i int) {
ls.v.Elem().Set(ls.v.Elem().Slice(0, i))
}
-func (ls *listReflect) NewElement() pref.Value {
+func (ls *listReflect) NewElement() protoreflect.Value {
return ls.conv.New()
}
func (ls *listReflect) IsValid() bool {
diff --git a/internal/impl/convert_map.go b/internal/impl/convert_map.go
index de06b259..f30b0a05 100644
--- a/internal/impl/convert_map.go
+++ b/internal/impl/convert_map.go
@@ -8,7 +8,7 @@ import (
"fmt"
"reflect"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
type mapConverter struct {
@@ -16,7 +16,7 @@ type mapConverter struct {
keyConv, valConv Converter
}
-func newMapConverter(t reflect.Type, fd pref.FieldDescriptor) *mapConverter {
+func newMapConverter(t reflect.Type, fd protoreflect.FieldDescriptor) *mapConverter {
if t.Kind() != reflect.Map {
panic(fmt.Sprintf("invalid Go type %v for field %v", t, fd.FullName()))
}
@@ -27,18 +27,18 @@ func newMapConverter(t reflect.Type, fd pref.FieldDescriptor) *mapConverter {
}
}
-func (c *mapConverter) PBValueOf(v reflect.Value) pref.Value {
+func (c *mapConverter) PBValueOf(v reflect.Value) protoreflect.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
- return pref.ValueOfMap(&mapReflect{v, c.keyConv, c.valConv})
+ return protoreflect.ValueOfMap(&mapReflect{v, c.keyConv, c.valConv})
}
-func (c *mapConverter) GoValueOf(v pref.Value) reflect.Value {
+func (c *mapConverter) GoValueOf(v protoreflect.Value) reflect.Value {
return v.Map().(*mapReflect).v
}
-func (c *mapConverter) IsValidPB(v pref.Value) bool {
+func (c *mapConverter) IsValidPB(v protoreflect.Value) bool {
mapv, ok := v.Interface().(*mapReflect)
if !ok {
return false
@@ -50,11 +50,11 @@ func (c *mapConverter) IsValidGo(v reflect.Value) bool {
return v.IsValid() && v.Type() == c.goType
}
-func (c *mapConverter) New() pref.Value {
+func (c *mapConverter) New() protoreflect.Value {
return c.PBValueOf(reflect.MakeMap(c.goType))
}
-func (c *mapConverter) Zero() pref.Value {
+func (c *mapConverter) Zero() protoreflect.Value {
return c.PBValueOf(reflect.Zero(c.goType))
}
@@ -67,29 +67,29 @@ type mapReflect struct {
func (ms *mapReflect) Len() int {
return ms.v.Len()
}
-func (ms *mapReflect) Has(k pref.MapKey) bool {
+func (ms *mapReflect) Has(k protoreflect.MapKey) bool {
rk := ms.keyConv.GoValueOf(k.Value())
rv := ms.v.MapIndex(rk)
return rv.IsValid()
}
-func (ms *mapReflect) Get(k pref.MapKey) pref.Value {
+func (ms *mapReflect) Get(k protoreflect.MapKey) protoreflect.Value {
rk := ms.keyConv.GoValueOf(k.Value())
rv := ms.v.MapIndex(rk)
if !rv.IsValid() {
- return pref.Value{}
+ return protoreflect.Value{}
}
return ms.valConv.PBValueOf(rv)
}
-func (ms *mapReflect) Set(k pref.MapKey, v pref.Value) {
+func (ms *mapReflect) Set(k protoreflect.MapKey, v protoreflect.Value) {
rk := ms.keyConv.GoValueOf(k.Value())
rv := ms.valConv.GoValueOf(v)
ms.v.SetMapIndex(rk, rv)
}
-func (ms *mapReflect) Clear(k pref.MapKey) {
+func (ms *mapReflect) Clear(k protoreflect.MapKey) {
rk := ms.keyConv.GoValueOf(k.Value())
ms.v.SetMapIndex(rk, reflect.Value{})
}
-func (ms *mapReflect) Mutable(k pref.MapKey) pref.Value {
+func (ms *mapReflect) Mutable(k protoreflect.MapKey) protoreflect.Value {
if _, ok := ms.valConv.(*messageConverter); !ok {
panic("invalid Mutable on map with non-message value type")
}
@@ -100,7 +100,7 @@ func (ms *mapReflect) Mutable(k pref.MapKey) pref.Value {
}
return v
}
-func (ms *mapReflect) Range(f func(pref.MapKey, pref.Value) bool) {
+func (ms *mapReflect) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) {
iter := mapRange(ms.v)
for iter.Next() {
k := ms.keyConv.PBValueOf(iter.Key()).MapKey()
@@ -110,7 +110,7 @@ func (ms *mapReflect) Range(f func(pref.MapKey, pref.Value) bool) {
}
}
}
-func (ms *mapReflect) NewValue() pref.Value {
+func (ms *mapReflect) NewValue() protoreflect.Value {
return ms.valConv.New()
}
func (ms *mapReflect) IsValid() bool {
diff --git a/internal/impl/enum.go b/internal/impl/enum.go
index 8c1eab4b..5f3ef5ad 100644
--- a/internal/impl/enum.go
+++ b/internal/impl/enum.go
@@ -7,15 +7,15 @@ package impl
import (
"reflect"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
type EnumInfo struct {
GoReflectType reflect.Type // int32 kind
- Desc pref.EnumDescriptor
+ Desc protoreflect.EnumDescriptor
}
-func (t *EnumInfo) New(n pref.EnumNumber) pref.Enum {
- return reflect.ValueOf(n).Convert(t.GoReflectType).Interface().(pref.Enum)
+func (t *EnumInfo) New(n protoreflect.EnumNumber) protoreflect.Enum {
+ return reflect.ValueOf(n).Convert(t.GoReflectType).Interface().(protoreflect.Enum)
}
-func (t *EnumInfo) Descriptor() pref.EnumDescriptor { return t.Desc }
+func (t *EnumInfo) Descriptor() protoreflect.EnumDescriptor { return t.Desc }
diff --git a/internal/impl/enum_test.go b/internal/impl/enum_test.go
index 7e04500a..8fdac1c5 100644
--- a/internal/impl/enum_test.go
+++ b/internal/impl/enum_test.go
@@ -7,14 +7,14 @@ package impl_test
import (
"testing"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
testpb "google.golang.org/protobuf/internal/testprotos/test"
)
func TestEnum(t *testing.T) {
et := testpb.ForeignEnum_FOREIGN_FOO.Type()
- if got, want := et.New(pref.EnumNumber(testpb.ForeignEnum_FOREIGN_FOO)), pref.Enum(testpb.ForeignEnum_FOREIGN_FOO); got != want {
+ if got, want := et.New(protoreflect.EnumNumber(testpb.ForeignEnum_FOREIGN_FOO)), protoreflect.Enum(testpb.ForeignEnum_FOREIGN_FOO); got != want {
t.Errorf("testpb.ForeignEnum_FOREIGN_FOO.Type().New() = %[1]T(%[1]v), want %[2]T(%[2]v)", got, want)
}
}
diff --git a/internal/impl/extension.go b/internal/impl/extension.go
index e904fd99..cb25b0ba 100644
--- a/internal/impl/extension.go
+++ b/internal/impl/extension.go
@@ -9,8 +9,8 @@ import (
"sync"
"sync/atomic"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- piface "google.golang.org/protobuf/runtime/protoiface"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/runtime/protoiface"
)
// ExtensionInfo implements ExtensionType.
@@ -45,7 +45,7 @@ type ExtensionInfo struct {
// since the message may no longer implement the MessageV1 interface.
//
// Deprecated: Use the ExtendedType method instead.
- ExtendedType piface.MessageV1
+ ExtendedType protoiface.MessageV1
// ExtensionType is the zero value of the extension type.
//
@@ -83,31 +83,31 @@ const (
extensionInfoFullInit = 2
)
-func InitExtensionInfo(xi *ExtensionInfo, xd pref.ExtensionDescriptor, goType reflect.Type) {
+func InitExtensionInfo(xi *ExtensionInfo, xd protoreflect.ExtensionDescriptor, goType reflect.Type) {
xi.goType = goType
xi.desc = extensionTypeDescriptor{xd, xi}
xi.init = extensionInfoDescInit
}
-func (xi *ExtensionInfo) New() pref.Value {
+func (xi *ExtensionInfo) New() protoreflect.Value {
return xi.lazyInit().New()
}
-func (xi *ExtensionInfo) Zero() pref.Value {
+func (xi *ExtensionInfo) Zero() protoreflect.Value {
return xi.lazyInit().Zero()
}
-func (xi *ExtensionInfo) ValueOf(v interface{}) pref.Value {
+func (xi *ExtensionInfo) ValueOf(v interface{}) protoreflect.Value {
return xi.lazyInit().PBValueOf(reflect.ValueOf(v))
}
-func (xi *ExtensionInfo) InterfaceOf(v pref.Value) interface{} {
+func (xi *ExtensionInfo) InterfaceOf(v protoreflect.Value) interface{} {
return xi.lazyInit().GoValueOf(v).Interface()
}
-func (xi *ExtensionInfo) IsValidValue(v pref.Value) bool {
+func (xi *ExtensionInfo) IsValidValue(v protoreflect.Value) bool {
return xi.lazyInit().IsValidPB(v)
}
func (xi *ExtensionInfo) IsValidInterface(v interface{}) bool {
return xi.lazyInit().IsValidGo(reflect.ValueOf(v))
}
-func (xi *ExtensionInfo) TypeDescriptor() pref.ExtensionTypeDescriptor {
+func (xi *ExtensionInfo) TypeDescriptor() protoreflect.ExtensionTypeDescriptor {
if atomic.LoadUint32(&xi.init) < extensionInfoDescInit {
xi.lazyInitSlow()
}
@@ -144,13 +144,13 @@ func (xi *ExtensionInfo) lazyInitSlow() {
}
type extensionTypeDescriptor struct {
- pref.ExtensionDescriptor
+ protoreflect.ExtensionDescriptor
xi *ExtensionInfo
}
-func (xtd *extensionTypeDescriptor) Type() pref.ExtensionType {
+func (xtd *extensionTypeDescriptor) Type() protoreflect.ExtensionType {
return xtd.xi
}
-func (xtd *extensionTypeDescriptor) Descriptor() pref.ExtensionDescriptor {
+func (xtd *extensionTypeDescriptor) Descriptor() protoreflect.ExtensionDescriptor {
return xtd.ExtensionDescriptor
}
diff --git a/internal/impl/extension_test.go b/internal/impl/extension_test.go
index 171f3122..e1868a5f 100644
--- a/internal/impl/extension_test.go
+++ b/internal/impl/extension_test.go
@@ -11,7 +11,7 @@ import (
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
testpb "google.golang.org/protobuf/internal/testprotos/test"
)
@@ -23,7 +23,7 @@ func TestExtensionType(t *testing.T) {
}),
}
for _, test := range []struct {
- xt pref.ExtensionType
+ xt protoreflect.ExtensionType
value interface{}
}{
{
diff --git a/internal/impl/legacy_export.go b/internal/impl/legacy_export.go
index d007e8c1..9b64ad5b 100644
--- a/internal/impl/legacy_export.go
+++ b/internal/impl/legacy_export.go
@@ -12,21 +12,21 @@ import (
"reflect"
"google.golang.org/protobuf/internal/errors"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- piface "google.golang.org/protobuf/runtime/protoiface"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/runtime/protoiface"
)
// These functions exist to support exported APIs in generated protobufs.
// While these are deprecated, they cannot be removed for compatibility reasons.
// LegacyEnumName returns the name of enums used in legacy code.
-func (Export) LegacyEnumName(ed pref.EnumDescriptor) string {
+func (Export) LegacyEnumName(ed protoreflect.EnumDescriptor) string {
return legacyEnumName(ed)
}
// LegacyMessageTypeOf returns the protoreflect.MessageType for m,
// with name used as the message name if necessary.
-func (Export) LegacyMessageTypeOf(m piface.MessageV1, name pref.FullName) pref.MessageType {
+func (Export) LegacyMessageTypeOf(m protoiface.MessageV1, name protoreflect.FullName) protoreflect.MessageType {
if mv := (Export{}).protoMessageV2Of(m); mv != nil {
return mv.ProtoReflect().Type()
}
@@ -36,9 +36,9 @@ func (Export) LegacyMessageTypeOf(m piface.MessageV1, name pref.FullName) pref.M
// UnmarshalJSONEnum unmarshals an enum from a JSON-encoded input.
// The input can either be a string representing the enum value by name,
// or a number representing the enum number itself.
-func (Export) UnmarshalJSONEnum(ed pref.EnumDescriptor, b []byte) (pref.EnumNumber, error) {
+func (Export) UnmarshalJSONEnum(ed protoreflect.EnumDescriptor, b []byte) (protoreflect.EnumNumber, error) {
if b[0] == '"' {
- var name pref.Name
+ var name protoreflect.Name
if err := json.Unmarshal(b, &name); err != nil {
return 0, errors.New("invalid input for enum %v: %s", ed.FullName(), b)
}
@@ -48,7 +48,7 @@ func (Export) UnmarshalJSONEnum(ed pref.EnumDescriptor, b []byte) (pref.EnumNumb
}
return ev.Number(), nil
} else {
- var num pref.EnumNumber
+ var num protoreflect.EnumNumber
if err := json.Unmarshal(b, &num); err != nil {
return 0, errors.New("invalid input for enum %v: %s", ed.FullName(), b)
}
diff --git a/internal/impl/legacy_extension.go b/internal/impl/legacy_extension.go
index 49e72316..87b30d05 100644
--- a/internal/impl/legacy_extension.go
+++ b/internal/impl/legacy_extension.go
@@ -12,16 +12,16 @@ import (
ptag "google.golang.org/protobuf/internal/encoding/tag"
"google.golang.org/protobuf/internal/filedesc"
"google.golang.org/protobuf/internal/pragma"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- preg "google.golang.org/protobuf/reflect/protoregistry"
- piface "google.golang.org/protobuf/runtime/protoiface"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/runtime/protoiface"
)
func (xi *ExtensionInfo) initToLegacy() {
xd := xi.desc
- var parent piface.MessageV1
+ var parent protoiface.MessageV1
messageName := xd.ContainingMessage().FullName()
- if mt, _ := preg.GlobalTypes.FindMessageByName(messageName); mt != nil {
+ if mt, _ := protoregistry.GlobalTypes.FindMessageByName(messageName); mt != nil {
// Create a new parent message and unwrap it if possible.
mv := mt.New().Interface()
t := reflect.TypeOf(mv)
@@ -31,7 +31,7 @@ func (xi *ExtensionInfo) initToLegacy() {
// Check whether the message implements the legacy v1 Message interface.
mz := reflect.Zero(t).Interface()
- if mz, ok := mz.(piface.MessageV1); ok {
+ if mz, ok := mz.(protoiface.MessageV1); ok {
parent = mz
}
}
@@ -46,7 +46,7 @@ func (xi *ExtensionInfo) initToLegacy() {
// Reconstruct the legacy enum full name.
var enumName string
- if xd.Kind() == pref.EnumKind {
+ if xd.Kind() == protoreflect.EnumKind {
enumName = legacyEnumName(xd.Enum())
}
@@ -77,16 +77,16 @@ func (xi *ExtensionInfo) initFromLegacy() {
// field number is specified. In such a case, use a placeholder.
if xi.ExtendedType == nil || xi.ExtensionType == nil {
xd := placeholderExtension{
- name: pref.FullName(xi.Name),
- number: pref.FieldNumber(xi.Field),
+ name: protoreflect.FullName(xi.Name),
+ number: protoreflect.FieldNumber(xi.Field),
}
xi.desc = extensionTypeDescriptor{xd, xi}
return
}
// Resolve enum or message dependencies.
- var ed pref.EnumDescriptor
- var md pref.MessageDescriptor
+ var ed protoreflect.EnumDescriptor
+ var md protoreflect.MessageDescriptor
t := reflect.TypeOf(xi.ExtensionType)
isOptional := t.Kind() == reflect.Ptr && t.Elem().Kind() != reflect.Struct
isRepeated := t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8
@@ -94,18 +94,18 @@ func (xi *ExtensionInfo) initFromLegacy() {
t = t.Elem()
}
switch v := reflect.Zero(t).Interface().(type) {
- case pref.Enum:
+ case protoreflect.Enum:
ed = v.Descriptor()
case enumV1:
ed = LegacyLoadEnumDesc(t)
- case pref.ProtoMessage:
+ case protoreflect.ProtoMessage:
md = v.ProtoReflect().Descriptor()
case messageV1:
md = LegacyLoadMessageDesc(t)
}
// Derive basic field information from the struct tag.
- var evs pref.EnumValueDescriptors
+ var evs protoreflect.EnumValueDescriptors
if ed != nil {
evs = ed.Values()
}
@@ -114,8 +114,8 @@ func (xi *ExtensionInfo) initFromLegacy() {
// Construct a v2 ExtensionType.
xd := &filedesc.Extension{L2: new(filedesc.ExtensionL2)}
xd.L0.ParentFile = filedesc.SurrogateProto2
- xd.L0.FullName = pref.FullName(xi.Name)
- xd.L1.Number = pref.FieldNumber(xi.Field)
+ xd.L0.FullName = protoreflect.FullName(xi.Name)
+ xd.L1.Number = protoreflect.FieldNumber(xi.Field)
xd.L1.Cardinality = fd.L1.Cardinality
xd.L1.Kind = fd.L1.Kind
xd.L2.IsPacked = fd.L1.IsPacked
@@ -138,39 +138,39 @@ func (xi *ExtensionInfo) initFromLegacy() {
}
type placeholderExtension struct {
- name pref.FullName
- number pref.FieldNumber
+ name protoreflect.FullName
+ number protoreflect.FieldNumber
}
-func (x placeholderExtension) ParentFile() pref.FileDescriptor { return nil }
-func (x placeholderExtension) Parent() pref.Descriptor { return nil }
-func (x placeholderExtension) Index() int { return 0 }
-func (x placeholderExtension) Syntax() pref.Syntax { return 0 }
-func (x placeholderExtension) Name() pref.Name { return x.name.Name() }
-func (x placeholderExtension) FullName() pref.FullName { return x.name }
-func (x placeholderExtension) IsPlaceholder() bool { return true }
-func (x placeholderExtension) Options() pref.ProtoMessage { return descopts.Field }
-func (x placeholderExtension) Number() pref.FieldNumber { return x.number }
-func (x placeholderExtension) Cardinality() pref.Cardinality { return 0 }
-func (x placeholderExtension) Kind() pref.Kind { return 0 }
-func (x placeholderExtension) HasJSONName() bool { return false }
-func (x placeholderExtension) JSONName() string { return "[" + string(x.name) + "]" }
-func (x placeholderExtension) TextName() string { return "[" + string(x.name) + "]" }
-func (x placeholderExtension) HasPresence() bool { return false }
-func (x placeholderExtension) HasOptionalKeyword() bool { return false }
-func (x placeholderExtension) IsExtension() bool { return true }
-func (x placeholderExtension) IsWeak() bool { return false }
-func (x placeholderExtension) IsPacked() bool { return false }
-func (x placeholderExtension) IsList() bool { return false }
-func (x placeholderExtension) IsMap() bool { return false }
-func (x placeholderExtension) MapKey() pref.FieldDescriptor { return nil }
-func (x placeholderExtension) MapValue() pref.FieldDescriptor { return nil }
-func (x placeholderExtension) HasDefault() bool { return false }
-func (x placeholderExtension) Default() pref.Value { return pref.Value{} }
-func (x placeholderExtension) DefaultEnumValue() pref.EnumValueDescriptor { return nil }
-func (x placeholderExtension) ContainingOneof() pref.OneofDescriptor { return nil }
-func (x placeholderExtension) ContainingMessage() pref.MessageDescriptor { return nil }
-func (x placeholderExtension) Enum() pref.EnumDescriptor { return nil }
-func (x placeholderExtension) Message() pref.MessageDescriptor { return nil }
-func (x placeholderExtension) ProtoType(pref.FieldDescriptor) { return }
-func (x placeholderExtension) ProtoInternal(pragma.DoNotImplement) { return }
+func (x placeholderExtension) ParentFile() protoreflect.FileDescriptor { return nil }
+func (x placeholderExtension) Parent() protoreflect.Descriptor { return nil }
+func (x placeholderExtension) Index() int { return 0 }
+func (x placeholderExtension) Syntax() protoreflect.Syntax { return 0 }
+func (x placeholderExtension) Name() protoreflect.Name { return x.name.Name() }
+func (x placeholderExtension) FullName() protoreflect.FullName { return x.name }
+func (x placeholderExtension) IsPlaceholder() bool { return true }
+func (x placeholderExtension) Options() protoreflect.ProtoMessage { return descopts.Field }
+func (x placeholderExtension) Number() protoreflect.FieldNumber { return x.number }
+func (x placeholderExtension) Cardinality() protoreflect.Cardinality { return 0 }
+func (x placeholderExtension) Kind() protoreflect.Kind { return 0 }
+func (x placeholderExtension) HasJSONName() bool { return false }
+func (x placeholderExtension) JSONName() string { return "[" + string(x.name) + "]" }
+func (x placeholderExtension) TextName() string { return "[" + string(x.name) + "]" }
+func (x placeholderExtension) HasPresence() bool { return false }
+func (x placeholderExtension) HasOptionalKeyword() bool { return false }
+func (x placeholderExtension) IsExtension() bool { return true }
+func (x placeholderExtension) IsWeak() bool { return false }
+func (x placeholderExtension) IsPacked() bool { return false }
+func (x placeholderExtension) IsList() bool { return false }
+func (x placeholderExtension) IsMap() bool { return false }
+func (x placeholderExtension) MapKey() protoreflect.FieldDescriptor { return nil }
+func (x placeholderExtension) MapValue() protoreflect.FieldDescriptor { return nil }
+func (x placeholderExtension) HasDefault() bool { return false }
+func (x placeholderExtension) Default() protoreflect.Value { return protoreflect.Value{} }
+func (x placeholderExtension) DefaultEnumValue() protoreflect.EnumValueDescriptor { return nil }
+func (x placeholderExtension) ContainingOneof() protoreflect.OneofDescriptor { return nil }
+func (x placeholderExtension) ContainingMessage() protoreflect.MessageDescriptor { return nil }
+func (x placeholderExtension) Enum() protoreflect.EnumDescriptor { return nil }
+func (x placeholderExtension) Message() protoreflect.MessageDescriptor { return nil }
+func (x placeholderExtension) ProtoType(protoreflect.FieldDescriptor) { return }
+func (x placeholderExtension) ProtoInternal(pragma.DoNotImplement) { return }
diff --git a/internal/impl/legacy_file_test.go b/internal/impl/legacy_file_test.go
index e59f0a03..66600eec 100644
--- a/internal/impl/legacy_file_test.go
+++ b/internal/impl/legacy_file_test.go
@@ -16,8 +16,8 @@ import (
"google.golang.org/protobuf/internal/impl"
"google.golang.org/protobuf/internal/pragma"
"google.golang.org/protobuf/proto"
- pdesc "google.golang.org/protobuf/reflect/protodesc"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protodesc"
+ "google.golang.org/protobuf/reflect/protoreflect"
proto2_20160225 "google.golang.org/protobuf/internal/testprotos/legacy/proto2_20160225_2fc053c5"
proto2_20160519 "google.golang.org/protobuf/internal/testprotos/legacy/proto2_20160519_a4ab9ec5"
@@ -34,7 +34,7 @@ import (
"google.golang.org/protobuf/types/descriptorpb"
)
-func mustLoadFileDesc(b []byte, _ []int) pref.FileDescriptor {
+func mustLoadFileDesc(b []byte, _ []int) protoreflect.FileDescriptor {
zr, err := gzip.NewReader(bytes.NewReader(b))
if err != nil {
panic(err)
@@ -48,7 +48,7 @@ func mustLoadFileDesc(b []byte, _ []int) pref.FileDescriptor {
if err != nil {
panic(err)
}
- fd, err := pdesc.NewFile(p, nil)
+ fd, err := protodesc.NewFile(p, nil)
if err != nil {
panic(err)
}
@@ -56,10 +56,10 @@ func mustLoadFileDesc(b []byte, _ []int) pref.FileDescriptor {
}
func TestDescriptor(t *testing.T) {
- var tests []struct{ got, want pref.Descriptor }
+ var tests []struct{ got, want protoreflect.Descriptor }
fileDescP2_20160225 := mustLoadFileDesc(new(proto2_20160225.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto2_20160225.SiblingEnum(0))),
want: fileDescP2_20160225.Enums().ByName("SiblingEnum"),
}, {
@@ -98,7 +98,7 @@ func TestDescriptor(t *testing.T) {
}}...)
fileDescP3_20160225 := mustLoadFileDesc(new(proto3_20160225.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto3_20160225.SiblingEnum(0))),
want: fileDescP3_20160225.Enums().ByName("SiblingEnum"),
}, {
@@ -116,7 +116,7 @@ func TestDescriptor(t *testing.T) {
}}...)
fileDescP2_20160519 := mustLoadFileDesc(new(proto2_20160519.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto2_20160519.SiblingEnum(0))),
want: fileDescP2_20160519.Enums().ByName("SiblingEnum"),
}, {
@@ -155,7 +155,7 @@ func TestDescriptor(t *testing.T) {
}}...)
fileDescP3_20160519 := mustLoadFileDesc(new(proto3_20160519.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto3_20160519.SiblingEnum(0))),
want: fileDescP3_20160519.Enums().ByName("SiblingEnum"),
}, {
@@ -173,7 +173,7 @@ func TestDescriptor(t *testing.T) {
}}...)
fileDescP2_20180125 := mustLoadFileDesc(new(proto2_20180125.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto2_20180125.SiblingEnum(0))),
want: fileDescP2_20180125.Enums().ByName("SiblingEnum"),
}, {
@@ -212,7 +212,7 @@ func TestDescriptor(t *testing.T) {
}}...)
fileDescP3_20180125 := mustLoadFileDesc(new(proto3_20180125.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto3_20180125.SiblingEnum(0))),
want: fileDescP3_20180125.Enums().ByName("SiblingEnum"),
}, {
@@ -230,7 +230,7 @@ func TestDescriptor(t *testing.T) {
}}...)
fileDescP2_20180430 := mustLoadFileDesc(new(proto2_20180430.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto2_20180430.SiblingEnum(0))),
want: fileDescP2_20180430.Enums().ByName("SiblingEnum"),
}, {
@@ -269,7 +269,7 @@ func TestDescriptor(t *testing.T) {
}}...)
fileDescP3_20180430 := mustLoadFileDesc(new(proto3_20180430.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto3_20180430.SiblingEnum(0))),
want: fileDescP3_20180430.Enums().ByName("SiblingEnum"),
}, {
@@ -287,7 +287,7 @@ func TestDescriptor(t *testing.T) {
}}...)
fileDescP2_20180814 := mustLoadFileDesc(new(proto2_20180814.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto2_20180814.SiblingEnum(0))),
want: fileDescP2_20180814.Enums().ByName("SiblingEnum"),
}, {
@@ -326,7 +326,7 @@ func TestDescriptor(t *testing.T) {
}}...)
fileDescP3_20180814 := mustLoadFileDesc(new(proto3_20180814.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto3_20180814.SiblingEnum(0))),
want: fileDescP3_20180814.Enums().ByName("SiblingEnum"),
}, {
@@ -344,7 +344,7 @@ func TestDescriptor(t *testing.T) {
}}...)
fileDescP2_20190205 := mustLoadFileDesc(new(proto2_20190205.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto2_20190205.SiblingEnum(0))),
want: fileDescP2_20190205.Enums().ByName("SiblingEnum"),
}, {
@@ -383,7 +383,7 @@ func TestDescriptor(t *testing.T) {
}}...)
fileDescP3_20190205 := mustLoadFileDesc(new(proto3_20190205.Message).Descriptor())
- tests = append(tests, []struct{ got, want pref.Descriptor }{{
+ tests = append(tests, []struct{ got, want protoreflect.Descriptor }{{
got: impl.LegacyLoadEnumDesc(reflect.TypeOf(proto3_20190205.SiblingEnum(0))),
want: fileDescP3_20190205.Enums().ByName("SiblingEnum"),
}, {
@@ -415,7 +415,7 @@ func TestDescriptor(t *testing.T) {
}
return out
}),
- cmp.Transformer("", func(x pref.Descriptor) map[string]interface{} {
+ cmp.Transformer("", func(x protoreflect.Descriptor) map[string]interface{} {
out := make(map[string]interface{})
v := reflect.ValueOf(x)
for i := 0; i < v.NumMethod(); i++ {
@@ -441,7 +441,7 @@ func TestDescriptor(t *testing.T) {
// TODO: Cycle support in cmp would be useful here.
v := m.Call(nil)[0]
if !v.IsNil() {
- out[name] = v.Interface().(pref.Descriptor).FullName()
+ out[name] = v.Interface().(protoreflect.Descriptor).FullName()
}
default:
out[name] = m.Call(nil)[0].Interface()
@@ -450,7 +450,7 @@ func TestDescriptor(t *testing.T) {
}
return out
}),
- cmp.Transformer("", func(v pref.Value) interface{} {
+ cmp.Transformer("", func(v protoreflect.Value) interface{} {
return v.Interface()
}),
}
diff --git a/internal/impl/legacy_test.go b/internal/impl/legacy_test.go
index f699568c..fe640018 100644
--- a/internal/impl/legacy_test.go
+++ b/internal/impl/legacy_test.go
@@ -17,10 +17,10 @@ import (
pimpl "google.golang.org/protobuf/internal/impl"
"google.golang.org/protobuf/internal/pragma"
"google.golang.org/protobuf/proto"
- pdesc "google.golang.org/protobuf/reflect/protodesc"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- preg "google.golang.org/protobuf/reflect/protoregistry"
- piface "google.golang.org/protobuf/runtime/protoiface"
+ "google.golang.org/protobuf/reflect/protodesc"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/runtime/protoiface"
proto2_20180125 "google.golang.org/protobuf/internal/testprotos/legacy/proto2_20180125_92554152"
"google.golang.org/protobuf/types/descriptorpb"
@@ -34,13 +34,13 @@ type LegacyTestMessage struct {
func (*LegacyTestMessage) Reset() {}
func (*LegacyTestMessage) String() string { return "" }
func (*LegacyTestMessage) ProtoMessage() {}
-func (*LegacyTestMessage) ExtensionRangeArray() []piface.ExtensionRangeV1 {
- return []piface.ExtensionRangeV1{{Start: 10, End: 20}, {Start: 40, End: 80}, {Start: 10000, End: 20000}}
+func (*LegacyTestMessage) ExtensionRangeArray() []protoiface.ExtensionRangeV1 {
+ return []protoiface.ExtensionRangeV1{{Start: 10, End: 20}, {Start: 40, End: 80}, {Start: 10000, End: 20000}}
}
func (*LegacyTestMessage) Descriptor() ([]byte, []int) { return legacyFD, []int{0} }
var legacyFD = func() []byte {
- b, _ := proto.Marshal(pdesc.ToFileDescriptorProto(mustMakeFileDesc(`
+ b, _ := proto.Marshal(protodesc.ToFileDescriptorProto(mustMakeFileDesc(`
name: "legacy.proto"
syntax: "proto2"
message_type: [{
@@ -53,11 +53,11 @@ var legacyFD = func() []byte {
func init() {
mt := pimpl.Export{}.MessageTypeOf((*LegacyTestMessage)(nil))
- preg.GlobalFiles.RegisterFile(mt.Descriptor().ParentFile())
- preg.GlobalTypes.RegisterMessage(mt)
+ protoregistry.GlobalFiles.RegisterFile(mt.Descriptor().ParentFile())
+ protoregistry.GlobalTypes.RegisterMessage(mt)
}
-func mustMakeExtensionType(fileDesc, extDesc string, t reflect.Type, r pdesc.Resolver) pref.ExtensionType {
+func mustMakeExtensionType(fileDesc, extDesc string, t reflect.Type, r protodesc.Resolver) protoreflect.ExtensionType {
s := fmt.Sprintf(`name:"test.proto" syntax:"proto2" %s extension:[{%s}]`, fileDesc, extDesc)
xd := mustMakeFileDesc(s, r).Extensions().Get(0)
xi := &pimpl.ExtensionInfo{}
@@ -65,12 +65,12 @@ func mustMakeExtensionType(fileDesc, extDesc string, t reflect.Type, r pdesc.Res
return xi
}
-func mustMakeFileDesc(s string, r pdesc.Resolver) pref.FileDescriptor {
+func mustMakeFileDesc(s string, r protodesc.Resolver) protoreflect.FileDescriptor {
pb := new(descriptorpb.FileDescriptorProto)
if err := prototext.Unmarshal([]byte(s), pb); err != nil {
panic(err)
}
- fd, err := pdesc.NewFile(pb, r)
+ fd, err := protodesc.NewFile(pb, r)
if err != nil {
panic(err)
}
@@ -90,7 +90,7 @@ var (
enumProto2Desc.ParentFile(),
testMessageV2Desc.ParentFile(),
)
- extensionTypes = []pref.ExtensionType{
+ extensionTypes = []protoreflect.ExtensionType{
mustMakeExtensionType(
`package:"fizz.buzz" dependency:"legacy.proto"`,
`name:"optional_bool" number:10000 label:LABEL_OPTIONAL type:TYPE_BOOL default_value:"true" extendee:".LegacyTestMessage"`,
@@ -466,11 +466,11 @@ func TestLegacyExtensionConvert(t *testing.T) {
wantType := extensionTypes[i]
wantDesc := extensionDescs[i]
- gotType := (pref.ExtensionType)(wantDesc)
+ gotType := (protoreflect.ExtensionType)(wantDesc)
gotDesc := wantType.(*pimpl.ExtensionInfo)
// Concurrently call accessors to trigger possible races.
- for _, xt := range []pref.ExtensionType{wantType, wantDesc} {
+ for _, xt := range []protoreflect.ExtensionType{wantType, wantDesc} {
xt := xt
go func() { xt.New() }()
go func() { xt.Zero() }()
@@ -495,7 +495,7 @@ func TestLegacyExtensionConvert(t *testing.T) {
}
return out
}),
- cmp.Transformer("", func(x pref.Descriptor) map[string]interface{} {
+ cmp.Transformer("", func(x protoreflect.Descriptor) map[string]interface{} {
out := make(map[string]interface{})
v := reflect.ValueOf(x)
for i := 0; i < v.NumMethod(); i++ {
@@ -513,7 +513,7 @@ func TestLegacyExtensionConvert(t *testing.T) {
// TODO: Cycle support in cmp would be useful here.
v := m.Call(nil)[0]
if !v.IsNil() {
- out[name] = v.Interface().(pref.Descriptor).FullName()
+ out[name] = v.Interface().(protoreflect.Descriptor).FullName()
}
case "Type":
// Ignore ExtensionTypeDescriptor.Type method to avoid cycle.
@@ -524,12 +524,12 @@ func TestLegacyExtensionConvert(t *testing.T) {
}
return out
}),
- cmp.Transformer("", func(xt pref.ExtensionType) map[string]interface{} {
+ cmp.Transformer("", func(xt protoreflect.ExtensionType) map[string]interface{} {
return map[string]interface{}{
"Descriptor": xt.TypeDescriptor(),
}
}),
- cmp.Transformer("", func(v pref.Value) interface{} {
+ cmp.Transformer("", func(v protoreflect.Value) interface{} {
return v.Interface()
}),
}
@@ -575,7 +575,7 @@ func (*MessageB) Descriptor() ([]byte, []int) { return concurrentFD, []int{1} }
func (Enum) EnumDescriptor() ([]byte, []int) { return concurrentFD, []int{0} }
var concurrentFD = func() []byte {
- b, _ := proto.Marshal(pdesc.ToFileDescriptorProto(mustMakeFileDesc(`
+ b, _ := proto.Marshal(protodesc.ToFileDescriptorProto(mustMakeFileDesc(`
name: "concurrent.proto"
syntax: "proto2"
package: "legacy"
@@ -606,9 +606,9 @@ var concurrentFD = func() []byte {
// results in the exact same descriptor being created.
func TestLegacyConcurrentInit(t *testing.T) {
const numParallel = 5
- var messageATypes [numParallel]pref.MessageType
- var messageBTypes [numParallel]pref.MessageType
- var enumDescs [numParallel]pref.EnumDescriptor
+ var messageATypes [numParallel]protoreflect.MessageType
+ var messageBTypes [numParallel]protoreflect.MessageType
+ var enumDescs [numParallel]protoreflect.EnumDescriptor
// Concurrently load message and enum types.
var wg sync.WaitGroup
@@ -690,9 +690,9 @@ func (*LegacyTestMessageName2) XXX_MessageName() string {
func TestLegacyMessageName(t *testing.T) {
tests := []struct {
- in piface.MessageV1
- suggestName pref.FullName
- wantName pref.FullName
+ in protoiface.MessageV1
+ suggestName protoreflect.FullName
+ wantName protoreflect.FullName
}{
{new(LegacyTestMessageName1), "google.golang.org.LegacyTestMessageName1", "google.golang.org.LegacyTestMessageName1"},
{new(LegacyTestMessageName2), "", "google.golang.org.LegacyTestMessageName2"},
diff --git a/internal/impl/merge.go b/internal/impl/merge.go
index c65bbc04..7e65f64f 100644
--- a/internal/impl/merge.go
+++ b/internal/impl/merge.go
@@ -9,8 +9,8 @@ import (
"reflect"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- piface "google.golang.org/protobuf/runtime/protoiface"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/runtime/protoiface"
)
type mergeOptions struct{}
@@ -20,17 +20,17 @@ func (o mergeOptions) Merge(dst, src proto.Message) {
}
// merge is protoreflect.Methods.Merge.
-func (mi *MessageInfo) merge(in piface.MergeInput) piface.MergeOutput {
+func (mi *MessageInfo) merge(in protoiface.MergeInput) protoiface.MergeOutput {
dp, ok := mi.getPointer(in.Destination)
if !ok {
- return piface.MergeOutput{}
+ return protoiface.MergeOutput{}
}
sp, ok := mi.getPointer(in.Source)
if !ok {
- return piface.MergeOutput{}
+ return protoiface.MergeOutput{}
}
mi.mergePointer(dp, sp, mergeOptions{})
- return piface.MergeOutput{Flags: piface.MergeComplete}
+ return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
}
func (mi *MessageInfo) mergePointer(dst, src pointer, opts mergeOptions) {
@@ -64,7 +64,7 @@ func (mi *MessageInfo) mergePointer(dst, src pointer, opts mergeOptions) {
continue
}
dx := (*dext)[num]
- var dv pref.Value
+ var dv protoreflect.Value
if dx.Type() == sx.Type() {
dv = dx.Value()
}
@@ -85,15 +85,15 @@ func (mi *MessageInfo) mergePointer(dst, src pointer, opts mergeOptions) {
}
}
-func mergeScalarValue(dst, src pref.Value, opts mergeOptions) pref.Value {
+func mergeScalarValue(dst, src protoreflect.Value, opts mergeOptions) protoreflect.Value {
return src
}
-func mergeBytesValue(dst, src pref.Value, opts mergeOptions) pref.Value {
- return pref.ValueOfBytes(append(emptyBuf[:], src.Bytes()...))
+func mergeBytesValue(dst, src protoreflect.Value, opts mergeOptions) protoreflect.Value {
+ return protoreflect.ValueOfBytes(append(emptyBuf[:], src.Bytes()...))
}
-func mergeListValue(dst, src pref.Value, opts mergeOptions) pref.Value {
+func mergeListValue(dst, src protoreflect.Value, opts mergeOptions) protoreflect.Value {
dstl := dst.List()
srcl := src.List()
for i, llen := 0, srcl.Len(); i < llen; i++ {
@@ -102,29 +102,29 @@ func mergeListValue(dst, src pref.Value, opts mergeOptions) pref.Value {
return dst
}
-func mergeBytesListValue(dst, src pref.Value, opts mergeOptions) pref.Value {
+func mergeBytesListValue(dst, src protoreflect.Value, opts mergeOptions) protoreflect.Value {
dstl := dst.List()
srcl := src.List()
for i, llen := 0, srcl.Len(); i < llen; i++ {
sb := srcl.Get(i).Bytes()
db := append(emptyBuf[:], sb...)
- dstl.Append(pref.ValueOfBytes(db))
+ dstl.Append(protoreflect.ValueOfBytes(db))
}
return dst
}
-func mergeMessageListValue(dst, src pref.Value, opts mergeOptions) pref.Value {
+func mergeMessageListValue(dst, src protoreflect.Value, opts mergeOptions) protoreflect.Value {
dstl := dst.List()
srcl := src.List()
for i, llen := 0, srcl.Len(); i < llen; i++ {
sm := srcl.Get(i).Message()
dm := proto.Clone(sm.Interface()).ProtoReflect()
- dstl.Append(pref.ValueOfMessage(dm))
+ dstl.Append(protoreflect.ValueOfMessage(dm))
}
return dst
}
-func mergeMessageValue(dst, src pref.Value, opts mergeOptions) pref.Value {
+func mergeMessageValue(dst, src protoreflect.Value, opts mergeOptions) protoreflect.Value {
opts.Merge(dst.Message().Interface(), src.Message().Interface())
return dst
}
diff --git a/internal/impl/message_reflect.go b/internal/impl/message_reflect.go
index 9488b726..33eca45f 100644
--- a/internal/impl/message_reflect.go
+++ b/internal/impl/message_reflect.go
@@ -10,17 +10,17 @@ import (
"google.golang.org/protobuf/internal/detrand"
"google.golang.org/protobuf/internal/pragma"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
type reflectMessageInfo struct {
- fields map[pref.FieldNumber]*fieldInfo
- oneofs map[pref.Name]*oneofInfo
+ fields map[protoreflect.FieldNumber]*fieldInfo
+ oneofs map[protoreflect.Name]*oneofInfo
// fieldTypes contains the zero value of an enum or message field.
// For lists, it contains the element type.
// For maps, it contains the entry value type.
- fieldTypes map[pref.FieldNumber]interface{}
+ fieldTypes map[protoreflect.FieldNumber]interface{}
// denseFields is a subset of fields where:
// 0 < fieldDesc.Number() < len(denseFields)
@@ -30,8 +30,8 @@ type reflectMessageInfo struct {
// rangeInfos is a list of all fields (not belonging to a oneof) and oneofs.
rangeInfos []interface{} // either *fieldInfo or *oneofInfo
- getUnknown func(pointer) pref.RawFields
- setUnknown func(pointer, pref.RawFields)
+ getUnknown func(pointer) protoreflect.RawFields
+ setUnknown func(pointer, protoreflect.RawFields)
extensionMap func(pointer) *extensionMap
nilMessage atomicNilMessage
@@ -52,7 +52,7 @@ func (mi *MessageInfo) makeReflectFuncs(t reflect.Type, si structInfo) {
// This code assumes that the struct is well-formed and panics if there are
// any discrepancies.
func (mi *MessageInfo) makeKnownFieldsFunc(si structInfo) {
- mi.fields = map[pref.FieldNumber]*fieldInfo{}
+ mi.fields = map[protoreflect.FieldNumber]*fieldInfo{}
md := mi.Desc
fds := md.Fields()
for i := 0; i < fds.Len(); i++ {
@@ -82,7 +82,7 @@ func (mi *MessageInfo) makeKnownFieldsFunc(si structInfo) {
mi.fields[fd.Number()] = &fi
}
- mi.oneofs = map[pref.Name]*oneofInfo{}
+ mi.oneofs = map[protoreflect.Name]*oneofInfo{}
for i := 0; i < md.Oneofs().Len(); i++ {
od := md.Oneofs().Get(i)
mi.oneofs[od.Name()] = makeOneofInfo(od, si, mi.Exporter)
@@ -117,13 +117,13 @@ func (mi *MessageInfo) makeUnknownFieldsFunc(t reflect.Type, si structInfo) {
switch {
case si.unknownOffset.IsValid() && si.unknownType == unknownFieldsAType:
// Handle as []byte.
- mi.getUnknown = func(p pointer) pref.RawFields {
+ mi.getUnknown = func(p pointer) protoreflect.RawFields {
if p.IsNil() {
return nil
}
return *p.Apply(mi.unknownOffset).Bytes()
}
- mi.setUnknown = func(p pointer, b pref.RawFields) {
+ mi.setUnknown = func(p pointer, b protoreflect.RawFields) {
if p.IsNil() {
panic("invalid SetUnknown on nil Message")
}
@@ -131,7 +131,7 @@ func (mi *MessageInfo) makeUnknownFieldsFunc(t reflect.Type, si structInfo) {
}
case si.unknownOffset.IsValid() && si.unknownType == unknownFieldsBType:
// Handle as *[]byte.
- mi.getUnknown = func(p pointer) pref.RawFields {
+ mi.getUnknown = func(p pointer) protoreflect.RawFields {
if p.IsNil() {
return nil
}
@@ -141,7 +141,7 @@ func (mi *MessageInfo) makeUnknownFieldsFunc(t reflect.Type, si structInfo) {
}
return **bp
}
- mi.setUnknown = func(p pointer, b pref.RawFields) {
+ mi.setUnknown = func(p pointer, b protoreflect.RawFields) {
if p.IsNil() {
panic("invalid SetUnknown on nil Message")
}
@@ -152,10 +152,10 @@ func (mi *MessageInfo) makeUnknownFieldsFunc(t reflect.Type, si structInfo) {
**bp = b
}
default:
- mi.getUnknown = func(pointer) pref.RawFields {
+ mi.getUnknown = func(pointer) protoreflect.RawFields {
return nil
}
- mi.setUnknown = func(p pointer, _ pref.RawFields) {
+ mi.setUnknown = func(p pointer, _ protoreflect.RawFields) {
if p.IsNil() {
panic("invalid SetUnknown on nil Message")
}
@@ -224,7 +224,7 @@ func (mi *MessageInfo) makeFieldTypes(si structInfo) {
}
if ft != nil {
if mi.fieldTypes == nil {
- mi.fieldTypes = make(map[pref.FieldNumber]interface{})
+ mi.fieldTypes = make(map[protoreflect.FieldNumber]interface{})
}
mi.fieldTypes[fd.Number()] = reflect.Zero(ft).Interface()
}
@@ -233,7 +233,7 @@ func (mi *MessageInfo) makeFieldTypes(si structInfo) {
type extensionMap map[int32]ExtensionField
-func (m *extensionMap) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
+func (m *extensionMap) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
if m != nil {
for _, x := range *m {
xd := x.Type().TypeDescriptor()
@@ -247,7 +247,7 @@ func (m *extensionMap) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
}
}
}
-func (m *extensionMap) Has(xt pref.ExtensionType) (ok bool) {
+func (m *extensionMap) Has(xt protoreflect.ExtensionType) (ok bool) {
if m == nil {
return false
}
@@ -266,10 +266,10 @@ func (m *extensionMap) Has(xt pref.ExtensionType) (ok bool) {
}
return true
}
-func (m *extensionMap) Clear(xt pref.ExtensionType) {
+func (m *extensionMap) Clear(xt protoreflect.ExtensionType) {
delete(*m, int32(xt.TypeDescriptor().Number()))
}
-func (m *extensionMap) Get(xt pref.ExtensionType) pref.Value {
+func (m *extensionMap) Get(xt protoreflect.ExtensionType) protoreflect.Value {
xd := xt.TypeDescriptor()
if m != nil {
if x, ok := (*m)[int32(xd.Number())]; ok {
@@ -278,7 +278,7 @@ func (m *extensionMap) Get(xt pref.ExtensionType) pref.Value {
}
return xt.Zero()
}
-func (m *extensionMap) Set(xt pref.ExtensionType, v pref.Value) {
+func (m *extensionMap) Set(xt protoreflect.ExtensionType, v protoreflect.Value) {
xd := xt.TypeDescriptor()
isValid := true
switch {
@@ -302,9 +302,9 @@ func (m *extensionMap) Set(xt pref.ExtensionType, v pref.Value) {
x.Set(xt, v)
(*m)[int32(xd.Number())] = x
}
-func (m *extensionMap) Mutable(xt pref.ExtensionType) pref.Value {
+func (m *extensionMap) Mutable(xt protoreflect.ExtensionType) protoreflect.Value {
xd := xt.TypeDescriptor()
- if xd.Kind() != pref.MessageKind && xd.Kind() != pref.GroupKind && !xd.IsList() && !xd.IsMap() {
+ if xd.Kind() != protoreflect.MessageKind && xd.Kind() != protoreflect.GroupKind && !xd.IsList() && !xd.IsMap() {
panic("invalid Mutable on field with non-composite type")
}
if x, ok := (*m)[int32(xd.Number())]; ok {
@@ -368,8 +368,8 @@ type MessageState struct {
type messageState MessageState
var (
- _ pref.Message = (*messageState)(nil)
- _ unwrapper = (*messageState)(nil)
+ _ protoreflect.Message = (*messageState)(nil)
+ _ unwrapper = (*messageState)(nil)
)
// messageDataType is a tuple of a pointer to the message data and
@@ -387,16 +387,16 @@ type (
)
var (
- _ pref.Message = (*messageReflectWrapper)(nil)
- _ unwrapper = (*messageReflectWrapper)(nil)
- _ pref.ProtoMessage = (*messageIfaceWrapper)(nil)
- _ unwrapper = (*messageIfaceWrapper)(nil)
+ _ protoreflect.Message = (*messageReflectWrapper)(nil)
+ _ unwrapper = (*messageReflectWrapper)(nil)
+ _ protoreflect.ProtoMessage = (*messageIfaceWrapper)(nil)
+ _ unwrapper = (*messageIfaceWrapper)(nil)
)
// MessageOf returns a reflective view over a message. The input must be a
// pointer to a named Go struct. If the provided type has a ProtoReflect method,
// it must be implemented by calling this method.
-func (mi *MessageInfo) MessageOf(m interface{}) pref.Message {
+func (mi *MessageInfo) MessageOf(m interface{}) protoreflect.Message {
if reflect.TypeOf(m) != mi.GoReflectType {
panic(fmt.Sprintf("type mismatch: got %T, want %v", m, mi.GoReflectType))
}
@@ -421,7 +421,7 @@ func (m *messageIfaceWrapper) Reset() {
rv.Elem().Set(reflect.Zero(rv.Type().Elem()))
}
}
-func (m *messageIfaceWrapper) ProtoReflect() pref.Message {
+func (m *messageIfaceWrapper) ProtoReflect() protoreflect.Message {
return (*messageReflectWrapper)(m)
}
func (m *messageIfaceWrapper) protoUnwrap() interface{} {
@@ -430,7 +430,7 @@ func (m *messageIfaceWrapper) protoUnwrap() interface{} {
// checkField verifies that the provided field descriptor is valid.
// Exactly one of the returned values is populated.
-func (mi *MessageInfo) checkField(fd pref.FieldDescriptor) (*fieldInfo, pref.ExtensionType) {
+func (mi *MessageInfo) checkField(fd protoreflect.FieldDescriptor) (*fieldInfo, protoreflect.ExtensionType) {
var fi *fieldInfo
if n := fd.Number(); 0 < n && int(n) < len(mi.denseFields) {
fi = mi.denseFields[n]
@@ -455,7 +455,7 @@ func (mi *MessageInfo) checkField(fd pref.FieldDescriptor) (*fieldInfo, pref.Ext
if !mi.Desc.ExtensionRanges().Has(fd.Number()) {
panic(fmt.Sprintf("extension %v extends %v outside the extension range", fd.FullName(), mi.Desc.FullName()))
}
- xtd, ok := fd.(pref.ExtensionTypeDescriptor)
+ xtd, ok := fd.(protoreflect.ExtensionTypeDescriptor)
if !ok {
panic(fmt.Sprintf("extension %v does not implement protoreflect.ExtensionTypeDescriptor", fd.FullName()))
}
diff --git a/internal/impl/message_reflect_field.go b/internal/impl/message_reflect_field.go
index 343cf872..5e736c60 100644
--- a/internal/impl/message_reflect_field.go
+++ b/internal/impl/message_reflect_field.go
@@ -11,24 +11,24 @@ import (
"sync"
"google.golang.org/protobuf/internal/flags"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoregistry"
)
type fieldInfo struct {
- fieldDesc pref.FieldDescriptor
+ fieldDesc protoreflect.FieldDescriptor
// These fields are used for protobuf reflection support.
has func(pointer) bool
clear func(pointer)
- get func(pointer) pref.Value
- set func(pointer, pref.Value)
- mutable func(pointer) pref.Value
- newMessage func() pref.Message
- newField func() pref.Value
+ get func(pointer) protoreflect.Value
+ set func(pointer, protoreflect.Value)
+ mutable func(pointer) protoreflect.Value
+ newMessage func() protoreflect.Message
+ newField func() protoreflect.Value
}
-func fieldInfoForMissing(fd pref.FieldDescriptor) fieldInfo {
+func fieldInfoForMissing(fd protoreflect.FieldDescriptor) fieldInfo {
// This never occurs for generated message types.
// It implies that a hand-crafted type has missing Go fields
// for specific protobuf message fields.
@@ -40,19 +40,19 @@ func fieldInfoForMissing(fd pref.FieldDescriptor) fieldInfo {
clear: func(p pointer) {
panic("missing Go struct field for " + string(fd.FullName()))
},
- get: func(p pointer) pref.Value {
+ get: func(p pointer) protoreflect.Value {
return fd.Default()
},
- set: func(p pointer, v pref.Value) {
+ set: func(p pointer, v protoreflect.Value) {
panic("missing Go struct field for " + string(fd.FullName()))
},
- mutable: func(p pointer) pref.Value {
+ mutable: func(p pointer) protoreflect.Value {
panic("missing Go struct field for " + string(fd.FullName()))
},
- newMessage: func() pref.Message {
+ newMessage: func() protoreflect.Message {
panic("missing Go struct field for " + string(fd.FullName()))
},
- newField: func() pref.Value {
+ newField: func() protoreflect.Value {
if v := fd.Default(); v.IsValid() {
return v
}
@@ -61,7 +61,7 @@ func fieldInfoForMissing(fd pref.FieldDescriptor) fieldInfo {
}
}
-func fieldInfoForOneof(fd pref.FieldDescriptor, fs reflect.StructField, x exporter, ot reflect.Type) fieldInfo {
+func fieldInfoForOneof(fd protoreflect.FieldDescriptor, fs reflect.StructField, x exporter, ot reflect.Type) fieldInfo {
ft := fs.Type
if ft.Kind() != reflect.Interface {
panic(fmt.Sprintf("field %v has invalid type: got %v, want interface kind", fd.FullName(), ft))
@@ -102,7 +102,7 @@ func fieldInfoForOneof(fd pref.FieldDescriptor, fs reflect.StructField, x export
}
rv.Set(reflect.Zero(rv.Type()))
},
- get: func(p pointer) pref.Value {
+ get: func(p pointer) protoreflect.Value {
if p.IsNil() {
return conv.Zero()
}
@@ -113,7 +113,7 @@ func fieldInfoForOneof(fd pref.FieldDescriptor, fs reflect.StructField, x export
rv = rv.Elem().Elem().Field(0)
return conv.PBValueOf(rv)
},
- set: func(p pointer, v pref.Value) {
+ set: func(p pointer, v protoreflect.Value) {
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
if rv.IsNil() || rv.Elem().Type().Elem() != ot || rv.Elem().IsNil() {
rv.Set(reflect.New(ot))
@@ -121,7 +121,7 @@ func fieldInfoForOneof(fd pref.FieldDescriptor, fs reflect.StructField, x export
rv = rv.Elem().Elem().Field(0)
rv.Set(conv.GoValueOf(v))
},
- mutable: func(p pointer) pref.Value {
+ mutable: func(p pointer) protoreflect.Value {
if !isMessage {
panic(fmt.Sprintf("field %v with invalid Mutable call on field with non-composite type", fd.FullName()))
}
@@ -131,20 +131,20 @@ func fieldInfoForOneof(fd pref.FieldDescriptor, fs reflect.StructField, x export
}
rv = rv.Elem().Elem().Field(0)
if rv.Kind() == reflect.Ptr && rv.IsNil() {
- rv.Set(conv.GoValueOf(pref.ValueOfMessage(conv.New().Message())))
+ rv.Set(conv.GoValueOf(protoreflect.ValueOfMessage(conv.New().Message())))
}
return conv.PBValueOf(rv)
},
- newMessage: func() pref.Message {
+ newMessage: func() protoreflect.Message {
return conv.New().Message()
},
- newField: func() pref.Value {
+ newField: func() protoreflect.Value {
return conv.New()
},
}
}
-func fieldInfoForMap(fd pref.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
+func fieldInfoForMap(fd protoreflect.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
ft := fs.Type
if ft.Kind() != reflect.Map {
panic(fmt.Sprintf("field %v has invalid type: got %v, want map kind", fd.FullName(), ft))
@@ -166,7 +166,7 @@ func fieldInfoForMap(fd pref.FieldDescriptor, fs reflect.StructField, x exporter
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
rv.Set(reflect.Zero(rv.Type()))
},
- get: func(p pointer) pref.Value {
+ get: func(p pointer) protoreflect.Value {
if p.IsNil() {
return conv.Zero()
}
@@ -176,7 +176,7 @@ func fieldInfoForMap(fd pref.FieldDescriptor, fs reflect.StructField, x exporter
}
return conv.PBValueOf(rv)
},
- set: func(p pointer, v pref.Value) {
+ set: func(p pointer, v protoreflect.Value) {
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
pv := conv.GoValueOf(v)
if pv.IsNil() {
@@ -184,20 +184,20 @@ func fieldInfoForMap(fd pref.FieldDescriptor, fs reflect.StructField, x exporter
}
rv.Set(pv)
},
- mutable: func(p pointer) pref.Value {
+ mutable: func(p pointer) protoreflect.Value {
v := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
if v.IsNil() {
v.Set(reflect.MakeMap(fs.Type))
}
return conv.PBValueOf(v)
},
- newField: func() pref.Value {
+ newField: func() protoreflect.Value {
return conv.New()
},
}
}
-func fieldInfoForList(fd pref.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
+func fieldInfoForList(fd protoreflect.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
ft := fs.Type
if ft.Kind() != reflect.Slice {
panic(fmt.Sprintf("field %v has invalid type: got %v, want slice kind", fd.FullName(), ft))
@@ -219,7 +219,7 @@ func fieldInfoForList(fd pref.FieldDescriptor, fs reflect.StructField, x exporte
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
rv.Set(reflect.Zero(rv.Type()))
},
- get: func(p pointer) pref.Value {
+ get: func(p pointer) protoreflect.Value {
if p.IsNil() {
return conv.Zero()
}
@@ -229,7 +229,7 @@ func fieldInfoForList(fd pref.FieldDescriptor, fs reflect.StructField, x exporte
}
return conv.PBValueOf(rv)
},
- set: func(p pointer, v pref.Value) {
+ set: func(p pointer, v protoreflect.Value) {
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
pv := conv.GoValueOf(v)
if pv.IsNil() {
@@ -237,11 +237,11 @@ func fieldInfoForList(fd pref.FieldDescriptor, fs reflect.StructField, x exporte
}
rv.Set(pv.Elem())
},
- mutable: func(p pointer) pref.Value {
+ mutable: func(p pointer) protoreflect.Value {
v := p.Apply(fieldOffset).AsValueOf(fs.Type)
return conv.PBValueOf(v)
},
- newField: func() pref.Value {
+ newField: func() protoreflect.Value {
return conv.New()
},
}
@@ -252,7 +252,7 @@ var (
emptyBytes = reflect.ValueOf([]byte{})
)
-func fieldInfoForScalar(fd pref.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
+func fieldInfoForScalar(fd protoreflect.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
ft := fs.Type
nullable := fd.HasPresence()
isBytes := ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8
@@ -300,7 +300,7 @@ func fieldInfoForScalar(fd pref.FieldDescriptor, fs reflect.StructField, x expor
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
rv.Set(reflect.Zero(rv.Type()))
},
- get: func(p pointer) pref.Value {
+ get: func(p pointer) protoreflect.Value {
if p.IsNil() {
return conv.Zero()
}
@@ -315,7 +315,7 @@ func fieldInfoForScalar(fd pref.FieldDescriptor, fs reflect.StructField, x expor
}
return conv.PBValueOf(rv)
},
- set: func(p pointer, v pref.Value) {
+ set: func(p pointer, v protoreflect.Value) {
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
if nullable && rv.Kind() == reflect.Ptr {
if rv.IsNil() {
@@ -332,23 +332,23 @@ func fieldInfoForScalar(fd pref.FieldDescriptor, fs reflect.StructField, x expor
}
}
},
- newField: func() pref.Value {
+ newField: func() protoreflect.Value {
return conv.New()
},
}
}
-func fieldInfoForWeakMessage(fd pref.FieldDescriptor, weakOffset offset) fieldInfo {
+func fieldInfoForWeakMessage(fd protoreflect.FieldDescriptor, weakOffset offset) fieldInfo {
if !flags.ProtoLegacy {
panic("no support for proto1 weak fields")
}
var once sync.Once
- var messageType pref.MessageType
+ var messageType protoreflect.MessageType
lazyInit := func() {
once.Do(func() {
messageName := fd.Message().FullName()
- messageType, _ = preg.GlobalTypes.FindMessageByName(messageName)
+ messageType, _ = protoregistry.GlobalTypes.FindMessageByName(messageName)
if messageType == nil {
panic(fmt.Sprintf("weak message %v for field %v is not linked in", messageName, fd.FullName()))
}
@@ -368,18 +368,18 @@ func fieldInfoForWeakMessage(fd pref.FieldDescriptor, weakOffset offset) fieldIn
clear: func(p pointer) {
p.Apply(weakOffset).WeakFields().clear(num)
},
- get: func(p pointer) pref.Value {
+ get: func(p pointer) protoreflect.Value {
lazyInit()
if p.IsNil() {
- return pref.ValueOfMessage(messageType.Zero())
+ return protoreflect.ValueOfMessage(messageType.Zero())
}
m, ok := p.Apply(weakOffset).WeakFields().get(num)
if !ok {
- return pref.ValueOfMessage(messageType.Zero())
+ return protoreflect.ValueOfMessage(messageType.Zero())
}
- return pref.ValueOfMessage(m.ProtoReflect())
+ return protoreflect.ValueOfMessage(m.ProtoReflect())
},
- set: func(p pointer, v pref.Value) {
+ set: func(p pointer, v protoreflect.Value) {
lazyInit()
m := v.Message()
if m.Descriptor() != messageType.Descriptor() {
@@ -390,7 +390,7 @@ func fieldInfoForWeakMessage(fd pref.FieldDescriptor, weakOffset offset) fieldIn
}
p.Apply(weakOffset).WeakFields().set(num, m.Interface())
},
- mutable: func(p pointer) pref.Value {
+ mutable: func(p pointer) protoreflect.Value {
lazyInit()
fs := p.Apply(weakOffset).WeakFields()
m, ok := fs.get(num)
@@ -398,20 +398,20 @@ func fieldInfoForWeakMessage(fd pref.FieldDescriptor, weakOffset offset) fieldIn
m = messageType.New().Interface()
fs.set(num, m)
}
- return pref.ValueOfMessage(m.ProtoReflect())
+ return protoreflect.ValueOfMessage(m.ProtoReflect())
},
- newMessage: func() pref.Message {
+ newMessage: func() protoreflect.Message {
lazyInit()
return messageType.New()
},
- newField: func() pref.Value {
+ newField: func() protoreflect.Value {
lazyInit()
- return pref.ValueOfMessage(messageType.New())
+ return protoreflect.ValueOfMessage(messageType.New())
},
}
}
-func fieldInfoForMessage(fd pref.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
+func fieldInfoForMessage(fd protoreflect.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
ft := fs.Type
conv := NewConverter(ft, fd)
@@ -433,47 +433,47 @@ func fieldInfoForMessage(fd pref.FieldDescriptor, fs reflect.StructField, x expo
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
rv.Set(reflect.Zero(rv.Type()))
},
- get: func(p pointer) pref.Value {
+ get: func(p pointer) protoreflect.Value {
if p.IsNil() {
return conv.Zero()
}
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
return conv.PBValueOf(rv)
},
- set: func(p pointer, v pref.Value) {
+ set: func(p pointer, v protoreflect.Value) {
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
rv.Set(conv.GoValueOf(v))
if fs.Type.Kind() == reflect.Ptr && rv.IsNil() {
panic(fmt.Sprintf("field %v has invalid nil pointer", fd.FullName()))
}
},
- mutable: func(p pointer) pref.Value {
+ mutable: func(p pointer) protoreflect.Value {
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
if fs.Type.Kind() == reflect.Ptr && rv.IsNil() {
rv.Set(conv.GoValueOf(conv.New()))
}
return conv.PBValueOf(rv)
},
- newMessage: func() pref.Message {
+ newMessage: func() protoreflect.Message {
return conv.New().Message()
},
- newField: func() pref.Value {
+ newField: func() protoreflect.Value {
return conv.New()
},
}
}
type oneofInfo struct {
- oneofDesc pref.OneofDescriptor
- which func(pointer) pref.FieldNumber
+ oneofDesc protoreflect.OneofDescriptor
+ which func(pointer) protoreflect.FieldNumber
}
-func makeOneofInfo(od pref.OneofDescriptor, si structInfo, x exporter) *oneofInfo {
+func makeOneofInfo(od protoreflect.OneofDescriptor, si structInfo, x exporter) *oneofInfo {
oi := &oneofInfo{oneofDesc: od}
if od.IsSynthetic() {
fs := si.fieldsByNumber[od.Fields().Get(0).Number()]
fieldOffset := offsetOf(fs, x)
- oi.which = func(p pointer) pref.FieldNumber {
+ oi.which = func(p pointer) protoreflect.FieldNumber {
if p.IsNil() {
return 0
}
@@ -486,7 +486,7 @@ func makeOneofInfo(od pref.OneofDescriptor, si structInfo, x exporter) *oneofInf
} else {
fs := si.oneofsByName[od.Name()]
fieldOffset := offsetOf(fs, x)
- oi.which = func(p pointer) pref.FieldNumber {
+ oi.which = func(p pointer) protoreflect.FieldNumber {
if p.IsNil() {
return 0
}
diff --git a/internal/impl/message_reflect_test.go b/internal/impl/message_reflect_test.go
index 96c7e1b6..c14bdbd9 100644
--- a/internal/impl/message_reflect_test.go
+++ b/internal/impl/message_reflect_test.go
@@ -13,14 +13,14 @@ import (
"sync"
"testing"
- cmp "github.com/google/go-cmp/cmp"
- cmpopts "github.com/google/go-cmp/cmp/cmpopts"
+ "github.com/google/go-cmp/cmp"
+ "github.com/google/go-cmp/cmp/cmpopts"
"google.golang.org/protobuf/encoding/prototext"
pimpl "google.golang.org/protobuf/internal/impl"
"google.golang.org/protobuf/proto"
- pdesc "google.golang.org/protobuf/reflect/protodesc"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protodesc"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/testing/protopack"
@@ -44,28 +44,28 @@ type (
// Test operations performed on a message.
type (
// check that the message contents match
- equalMessage struct{ pref.Message }
+ equalMessage struct{ protoreflect.Message }
// check presence for specific fields in the message
- hasFields map[pref.FieldNumber]bool
+ hasFields map[protoreflect.FieldNumber]bool
// check that specific message fields match
- getFields map[pref.FieldNumber]pref.Value
+ getFields map[protoreflect.FieldNumber]protoreflect.Value
// set specific message fields
- setFields map[pref.FieldNumber]pref.Value
+ setFields map[protoreflect.FieldNumber]protoreflect.Value
// clear specific fields in the message
- clearFields []pref.FieldNumber
+ clearFields []protoreflect.FieldNumber
// check for the presence of specific oneof member fields.
- whichOneofs map[pref.Name]pref.FieldNumber
+ whichOneofs map[protoreflect.Name]protoreflect.FieldNumber
// apply messageOps on each specified message field
- messageFields map[pref.FieldNumber]messageOps
- messageFieldsMutable map[pref.FieldNumber]messageOps
+ messageFields map[protoreflect.FieldNumber]messageOps
+ messageFieldsMutable map[protoreflect.FieldNumber]messageOps
// apply listOps on each specified list field
- listFields map[pref.FieldNumber]listOps
- listFieldsMutable map[pref.FieldNumber]listOps
+ listFields map[protoreflect.FieldNumber]listOps
+ listFieldsMutable map[protoreflect.FieldNumber]listOps
// apply mapOps on each specified map fields
- mapFields map[pref.FieldNumber]mapOps
- mapFieldsMutable map[pref.FieldNumber]mapOps
+ mapFields map[protoreflect.FieldNumber]mapOps
+ mapFieldsMutable map[protoreflect.FieldNumber]mapOps
// range through all fields and check that they match
- rangeFields map[pref.FieldNumber]pref.Value
+ rangeFields map[protoreflect.FieldNumber]protoreflect.Value
)
func (equalMessage) isMessageOp() {}
@@ -85,15 +85,15 @@ func (rangeFields) isMessageOp() {}
// Test operations performed on a list.
type (
// check that the list contents match
- equalList struct{ pref.List }
+ equalList struct{ protoreflect.List }
// check that list length matches
lenList int
// check that specific list entries match
- getList map[int]pref.Value
+ getList map[int]protoreflect.Value
// set specific list entries
- setList map[int]pref.Value
+ setList map[int]protoreflect.Value
// append entries to the list
- appendList []pref.Value
+ appendList []protoreflect.Value
// apply messageOps on a newly appended message
appendMessageList messageOps
// truncate the list to the specified length
@@ -111,21 +111,21 @@ func (truncList) isListOp() {}
// Test operations performed on a map.
type (
// check that the map contents match
- equalMap struct{ pref.Map }
+ equalMap struct{ protoreflect.Map }
// check that map length matches
lenMap int
// check presence for specific entries in the map
hasMap map[interface{}]bool
// check that specific map entries match
- getMap map[interface{}]pref.Value
+ getMap map[interface{}]protoreflect.Value
// set specific map entries
- setMap map[interface{}]pref.Value
+ setMap map[interface{}]protoreflect.Value
// clear specific entries in the map
clearMap []interface{}
// apply messageOps on each specified message entry
messageMap map[interface{}]messageOps
// range through all entries and check that they match
- rangeMap map[interface{}]pref.Value
+ rangeMap map[interface{}]protoreflect.Value
)
func (equalMap) isMapOp() {}
@@ -163,34 +163,34 @@ type ScalarProto2 struct {
MyBytesA *MyString `protobuf:"22"`
}
-func mustMakeEnumDesc(path string, syntax pref.Syntax, enumDesc string) pref.EnumDescriptor {
+func mustMakeEnumDesc(path string, syntax protoreflect.Syntax, enumDesc string) protoreflect.EnumDescriptor {
s := fmt.Sprintf(`name:%q syntax:%q enum_type:[{%s}]`, path, syntax, enumDesc)
pb := new(descriptorpb.FileDescriptorProto)
if err := prototext.Unmarshal([]byte(s), pb); err != nil {
panic(err)
}
- fd, err := pdesc.NewFile(pb, nil)
+ fd, err := protodesc.NewFile(pb, nil)
if err != nil {
panic(err)
}
return fd.Enums().Get(0)
}
-func mustMakeMessageDesc(path string, syntax pref.Syntax, fileDesc, msgDesc string, r pdesc.Resolver) pref.MessageDescriptor {
+func mustMakeMessageDesc(path string, syntax protoreflect.Syntax, fileDesc, msgDesc string, r protodesc.Resolver) protoreflect.MessageDescriptor {
s := fmt.Sprintf(`name:%q syntax:%q %s message_type:[{%s}]`, path, syntax, fileDesc, msgDesc)
pb := new(descriptorpb.FileDescriptorProto)
if err := prototext.Unmarshal([]byte(s), pb); err != nil {
panic(err)
}
- fd, err := pdesc.NewFile(pb, r)
+ fd, err := protodesc.NewFile(pb, r)
if err != nil {
panic(err)
}
return fd.Messages().Get(0)
}
-var V = pref.ValueOf
-var VE = func(n pref.EnumNumber) pref.Value { return V(n) }
+var V = protoreflect.ValueOf
+var VE = func(n protoreflect.EnumNumber) protoreflect.Value { return V(n) }
type (
MyBool bool
@@ -210,7 +210,7 @@ type (
MapBytes map[MyString]MyBytes
)
-var scalarProto2Type = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(ScalarProto2)), Desc: mustMakeMessageDesc("scalar2.proto", pref.Proto2, "", `
+var scalarProto2Type = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(ScalarProto2)), Desc: mustMakeMessageDesc("scalar2.proto", protoreflect.Proto2, "", `
name: "ScalarProto2"
field: [
{name:"f1" number:1 label:LABEL_OPTIONAL type:TYPE_BOOL default_value:"true"},
@@ -240,7 +240,7 @@ var scalarProto2Type = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(Scala
`, nil),
}
-func (m *ScalarProto2) ProtoReflect() pref.Message { return scalarProto2Type.MessageOf(m) }
+func (m *ScalarProto2) ProtoReflect() protoreflect.Message { return scalarProto2Type.MessageOf(m) }
func TestScalarProto2(t *testing.T) {
testMessage(t, nil, new(ScalarProto2).ProtoReflect(), messageOps{
@@ -312,7 +312,7 @@ type ScalarProto3 struct {
MyBytesA MyString `protobuf:"22"`
}
-var scalarProto3Type = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(ScalarProto3)), Desc: mustMakeMessageDesc("scalar3.proto", pref.Proto3, "", `
+var scalarProto3Type = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(ScalarProto3)), Desc: mustMakeMessageDesc("scalar3.proto", protoreflect.Proto3, "", `
name: "ScalarProto3"
field: [
{name:"f1" number:1 label:LABEL_OPTIONAL type:TYPE_BOOL},
@@ -342,7 +342,7 @@ var scalarProto3Type = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(Scala
`, nil),
}
-func (m *ScalarProto3) ProtoReflect() pref.Message { return scalarProto3Type.MessageOf(m) }
+func (m *ScalarProto3) ProtoReflect() protoreflect.Message { return scalarProto3Type.MessageOf(m) }
func TestScalarProto3(t *testing.T) {
testMessage(t, nil, new(ScalarProto3).ProtoReflect(), messageOps{
@@ -432,7 +432,7 @@ type ListScalars struct {
MyBytes4 ListStrings `protobuf:"19"`
}
-var listScalarsType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(ListScalars)), Desc: mustMakeMessageDesc("list-scalars.proto", pref.Proto2, "", `
+var listScalarsType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(ListScalars)), Desc: mustMakeMessageDesc("list-scalars.proto", protoreflect.Proto2, "", `
name: "ListScalars"
field: [
{name:"f1" number:1 label:LABEL_REPEATED type:TYPE_BOOL},
@@ -460,7 +460,7 @@ var listScalarsType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(ListSc
`, nil),
}
-func (m *ListScalars) ProtoReflect() pref.Message { return listScalarsType.MessageOf(m) }
+func (m *ListScalars) ProtoReflect() protoreflect.Message { return listScalarsType.MessageOf(m) }
func TestListScalars(t *testing.T) {
empty := new(ListScalars).ProtoReflect()
@@ -585,7 +585,7 @@ type MapScalars struct {
MyBytes4 MapStrings `protobuf:"25"`
}
-var mapScalarsType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(MapScalars)), Desc: mustMakeMessageDesc("map-scalars.proto", pref.Proto2, "", `
+var mapScalarsType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(MapScalars)), Desc: mustMakeMessageDesc("map-scalars.proto", protoreflect.Proto2, "", `
name: "MapScalars"
field: [
{name:"f1" number:1 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".MapScalars.F1Entry"},
@@ -650,7 +650,7 @@ var mapScalarsType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(MapScal
`, nil),
}
-func (m *MapScalars) ProtoReflect() pref.Message { return mapScalarsType.MessageOf(m) }
+func (m *MapScalars) ProtoReflect() protoreflect.Message { return mapScalarsType.MessageOf(m) }
func TestMapScalars(t *testing.T) {
empty := new(MapScalars).ProtoReflect()
@@ -775,7 +775,7 @@ type OneofScalars struct {
Union isOneofScalars_Union `protobuf_oneof:"union"`
}
-var oneofScalarsType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(OneofScalars)), Desc: mustMakeMessageDesc("oneof-scalars.proto", pref.Proto2, "", `
+var oneofScalarsType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(OneofScalars)), Desc: mustMakeMessageDesc("oneof-scalars.proto", protoreflect.Proto2, "", `
name: "OneofScalars"
field: [
{name:"f1" number:1 label:LABEL_OPTIONAL type:TYPE_BOOL default_value:"true" oneof_index:0},
@@ -796,7 +796,7 @@ var oneofScalarsType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(Oneof
`, nil),
}
-func (m *OneofScalars) ProtoReflect() pref.Message { return oneofScalarsType.MessageOf(m) }
+func (m *OneofScalars) ProtoReflect() protoreflect.Message { return oneofScalarsType.MessageOf(m) }
func (*OneofScalars) XXX_OneofWrappers() []interface{} {
return []interface{}{
@@ -933,29 +933,29 @@ func TestOneofs(t *testing.T) {
type EnumProto2 int32
-var enumProto2Desc = mustMakeEnumDesc("enum2.proto", pref.Proto2, `
+var enumProto2Desc = mustMakeEnumDesc("enum2.proto", protoreflect.Proto2, `
name: "EnumProto2"
value: [{name:"DEAD" number:0xdead}, {name:"BEEF" number:0xbeef}]
`)
-func (e EnumProto2) Descriptor() pref.EnumDescriptor { return enumProto2Desc }
-func (e EnumProto2) Type() pref.EnumType { return e }
-func (e EnumProto2) Enum() *EnumProto2 { return &e }
-func (e EnumProto2) Number() pref.EnumNumber { return pref.EnumNumber(e) }
-func (t EnumProto2) New(n pref.EnumNumber) pref.Enum { return EnumProto2(n) }
+func (e EnumProto2) Descriptor() protoreflect.EnumDescriptor { return enumProto2Desc }
+func (e EnumProto2) Type() protoreflect.EnumType { return e }
+func (e EnumProto2) Enum() *EnumProto2 { return &e }
+func (e EnumProto2) Number() protoreflect.EnumNumber { return protoreflect.EnumNumber(e) }
+func (t EnumProto2) New(n protoreflect.EnumNumber) protoreflect.Enum { return EnumProto2(n) }
type EnumProto3 int32
-var enumProto3Desc = mustMakeEnumDesc("enum3.proto", pref.Proto3, `
+var enumProto3Desc = mustMakeEnumDesc("enum3.proto", protoreflect.Proto3, `
name: "EnumProto3",
value: [{name:"ALPHA" number:0}, {name:"BRAVO" number:1}]
`)
-func (e EnumProto3) Descriptor() pref.EnumDescriptor { return enumProto3Desc }
-func (e EnumProto3) Type() pref.EnumType { return e }
-func (e EnumProto3) Enum() *EnumProto3 { return &e }
-func (e EnumProto3) Number() pref.EnumNumber { return pref.EnumNumber(e) }
-func (t EnumProto3) New(n pref.EnumNumber) pref.Enum { return EnumProto3(n) }
+func (e EnumProto3) Descriptor() protoreflect.EnumDescriptor { return enumProto3Desc }
+func (e EnumProto3) Type() protoreflect.EnumType { return e }
+func (e EnumProto3) Enum() *EnumProto3 { return &e }
+func (e EnumProto3) Number() protoreflect.EnumNumber { return protoreflect.EnumNumber(e) }
+func (t EnumProto3) New(n protoreflect.EnumNumber) protoreflect.Enum { return EnumProto3(n) }
type EnumMessages struct {
EnumP2 *EnumProto2 `protobuf:"1"`
@@ -969,7 +969,7 @@ type EnumMessages struct {
Union isEnumMessages_Union `protobuf_oneof:"union"`
}
-var enumMessagesType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(EnumMessages)), Desc: mustMakeMessageDesc("enum-messages.proto", pref.Proto2, `
+var enumMessagesType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(EnumMessages)), Desc: mustMakeMessageDesc("enum-messages.proto", protoreflect.Proto2, `
dependency: ["enum2.proto", "enum3.proto", "scalar2.proto", "scalar3.proto", "proto2_20180125_92554152/test.proto"]
`, `
name: "EnumMessages"
@@ -1001,7 +1001,7 @@ var enumMessagesType = pimpl.MessageInfo{GoReflectType: reflect.TypeOf(new(EnumM
)),
}
-func newFileRegistry(files ...pref.FileDescriptor) *protoregistry.Files {
+func newFileRegistry(files ...protoreflect.FileDescriptor) *protoregistry.Files {
r := new(protoregistry.Files)
for _, file := range files {
r.RegisterFile(file)
@@ -1009,7 +1009,7 @@ func newFileRegistry(files ...pref.FileDescriptor) *protoregistry.Files {
return r
}
-func (m *EnumMessages) ProtoReflect() pref.Message { return enumMessagesType.MessageOf(m) }
+func (m *EnumMessages) ProtoReflect() protoreflect.Message { return enumMessagesType.MessageOf(m) }
func (*EnumMessages) XXX_OneofWrappers() []interface{} {
return []interface{}{
@@ -1161,24 +1161,24 @@ var cmpOpts = cmp.Options{
my := pimpl.Export{}.MessageOf(y).Interface()
return proto.Equal(mx, my)
}),
- cmp.Transformer("UnwrapValue", func(pv pref.Value) interface{} {
+ cmp.Transformer("UnwrapValue", func(pv protoreflect.Value) interface{} {
switch v := pv.Interface().(type) {
- case pref.Message:
- out := make(map[pref.FieldNumber]pref.Value)
- v.Range(func(fd pref.FieldDescriptor, v pref.Value) bool {
+ case protoreflect.Message:
+ out := make(map[protoreflect.FieldNumber]protoreflect.Value)
+ v.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
out[fd.Number()] = v
return true
})
return out
- case pref.List:
- var out []pref.Value
+ case protoreflect.List:
+ var out []protoreflect.Value
for i := 0; i < v.Len(); i++ {
out = append(out, v.Get(i))
}
return out
- case pref.Map:
- out := make(map[interface{}]pref.Value)
- v.Range(func(k pref.MapKey, v pref.Value) bool {
+ case protoreflect.Map:
+ out := make(map[interface{}]protoreflect.Value)
+ v.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool {
out[k.Interface()] = v
return true
})
@@ -1190,7 +1190,7 @@ var cmpOpts = cmp.Options{
cmpopts.EquateNaNs(),
}
-func testMessage(t *testing.T, p path, m pref.Message, tt messageOps) {
+func testMessage(t *testing.T, p path, m protoreflect.Message, tt messageOps) {
fieldDescs := m.Descriptor().Fields()
oneofDescs := m.Descriptor().Oneofs()
for i, op := range tt {
@@ -1201,8 +1201,8 @@ func testMessage(t *testing.T, p path, m pref.Message, tt messageOps) {
t.Errorf("operation %v, message mismatch (-want, +got):\n%s", p, diff)
}
case hasFields:
- got := map[pref.FieldNumber]bool{}
- want := map[pref.FieldNumber]bool(op)
+ got := map[protoreflect.FieldNumber]bool{}
+ want := map[protoreflect.FieldNumber]bool(op)
for n := range want {
fd := fieldDescs.ByNumber(n)
got[n] = m.Has(fd)
@@ -1211,8 +1211,8 @@ func testMessage(t *testing.T, p path, m pref.Message, tt messageOps) {
t.Errorf("operation %v, Message.Has mismatch (-want, +got):\n%s", p, diff)
}
case getFields:
- got := map[pref.FieldNumber]pref.Value{}
- want := map[pref.FieldNumber]pref.Value(op)
+ got := map[protoreflect.FieldNumber]protoreflect.Value{}
+ want := map[protoreflect.FieldNumber]protoreflect.Value(op)
for n := range want {
fd := fieldDescs.ByNumber(n)
got[n] = m.Get(fd)
@@ -1231,8 +1231,8 @@ func testMessage(t *testing.T, p path, m pref.Message, tt messageOps) {
m.Clear(fd)
}
case whichOneofs:
- got := map[pref.Name]pref.FieldNumber{}
- want := map[pref.Name]pref.FieldNumber(op)
+ got := map[protoreflect.Name]protoreflect.FieldNumber{}
+ want := map[protoreflect.Name]protoreflect.FieldNumber(op)
for s := range want {
od := oneofDescs.ByName(s)
fd := m.WhichOneof(od)
@@ -1288,9 +1288,9 @@ func testMessage(t *testing.T, p path, m pref.Message, tt messageOps) {
p.Pop()
}
case rangeFields:
- got := map[pref.FieldNumber]pref.Value{}
- want := map[pref.FieldNumber]pref.Value(op)
- m.Range(func(fd pref.FieldDescriptor, v pref.Value) bool {
+ got := map[protoreflect.FieldNumber]protoreflect.Value{}
+ want := map[protoreflect.FieldNumber]protoreflect.Value(op)
+ m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
got[fd.Number()] = v
return true
})
@@ -1304,7 +1304,7 @@ func testMessage(t *testing.T, p path, m pref.Message, tt messageOps) {
}
}
-func testLists(t *testing.T, p path, v pref.List, tt listOps) {
+func testLists(t *testing.T, p path, v protoreflect.List, tt listOps) {
for i, op := range tt {
p.Push(i)
switch op := op.(type) {
@@ -1317,8 +1317,8 @@ func testLists(t *testing.T, p path, v pref.List, tt listOps) {
t.Errorf("operation %v, List.Len = %d, want %d", p, got, want)
}
case getList:
- got := map[int]pref.Value{}
- want := map[int]pref.Value(op)
+ got := map[int]protoreflect.Value{}
+ want := map[int]protoreflect.Value(op)
for n := range want {
got[n] = v.Get(n)
}
@@ -1346,7 +1346,7 @@ func testLists(t *testing.T, p path, v pref.List, tt listOps) {
}
}
-func testMaps(t *testing.T, p path, m pref.Map, tt mapOps) {
+func testMaps(t *testing.T, p path, m protoreflect.Map, tt mapOps) {
for i, op := range tt {
p.Push(i)
switch op := op.(type) {
@@ -1368,8 +1368,8 @@ func testMaps(t *testing.T, p path, m pref.Map, tt mapOps) {
t.Errorf("operation %v, Map.Has mismatch (-want, +got):\n%s", p, diff)
}
case getMap:
- got := map[interface{}]pref.Value{}
- want := map[interface{}]pref.Value(op)
+ got := map[interface{}]protoreflect.Value{}
+ want := map[interface{}]protoreflect.Value(op)
for k := range want {
got[k] = m.Get(V(k).MapKey())
}
@@ -1393,9 +1393,9 @@ func testMaps(t *testing.T, p path, m pref.Map, tt mapOps) {
testMessage(t, p, m.Get(mk).Message(), tt)
}
case rangeMap:
- got := map[interface{}]pref.Value{}
- want := map[interface{}]pref.Value(op)
- m.Range(func(k pref.MapKey, v pref.Value) bool {
+ got := map[interface{}]protoreflect.Value{}
+ want := map[interface{}]protoreflect.Value(op)
+ m.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool {
got[k.Interface()] = v
return true
})
@@ -1409,7 +1409,7 @@ func testMaps(t *testing.T, p path, m pref.Map, tt mapOps) {
}
}
-func getField(m pref.Message, n pref.FieldNumber) pref.Value {
+func getField(m protoreflect.Message, n protoreflect.FieldNumber) protoreflect.Value {
fd := m.Descriptor().Fields().ByNumber(n)
return m.Get(fd)
}
@@ -1432,10 +1432,10 @@ type UnknownFieldsA struct {
var unknownFieldsAType = pimpl.MessageInfo{
GoReflectType: reflect.TypeOf(new(UnknownFieldsA)),
- Desc: mustMakeMessageDesc("unknown.proto", pref.Proto2, "", `name: "UnknownFieldsA"`, nil),
+ Desc: mustMakeMessageDesc("unknown.proto", protoreflect.Proto2, "", `name: "UnknownFieldsA"`, nil),
}
-func (m *UnknownFieldsA) ProtoReflect() pref.Message { return unknownFieldsAType.MessageOf(m) }
+func (m *UnknownFieldsA) ProtoReflect() protoreflect.Message { return unknownFieldsAType.MessageOf(m) }
type UnknownFieldsB struct {
XXX_unrecognized *[]byte
@@ -1443,10 +1443,10 @@ type UnknownFieldsB struct {
var unknownFieldsBType = pimpl.MessageInfo{
GoReflectType: reflect.TypeOf(new(UnknownFieldsB)),
- Desc: mustMakeMessageDesc("unknown.proto", pref.Proto2, "", `name: "UnknownFieldsB"`, nil),
+ Desc: mustMakeMessageDesc("unknown.proto", protoreflect.Proto2, "", `name: "UnknownFieldsB"`, nil),
}
-func (m *UnknownFieldsB) ProtoReflect() pref.Message { return unknownFieldsBType.MessageOf(m) }
+func (m *UnknownFieldsB) ProtoReflect() protoreflect.Message { return unknownFieldsBType.MessageOf(m) }
func TestUnknownFields(t *testing.T) {
for _, m := range []proto.Message{new(UnknownFieldsA), new(UnknownFieldsB)} {
@@ -1499,7 +1499,7 @@ func TestUnsafeAssumptions(t *testing.T) {
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
- var ms [10]pref.Message
+ var ms [10]protoreflect.Message
// Store the message only in its reflective form.
// Trigger the GC after each iteration.
@@ -1537,7 +1537,7 @@ func TestUnsafeAssumptions(t *testing.T) {
}
func BenchmarkName(b *testing.B) {
- var sink pref.FullName
+ var sink protoreflect.FullName
b.Run("Value", func(b *testing.B) {
b.ReportAllocs()
m := new(descriptorpb.FileDescriptorProto)
@@ -1558,7 +1558,7 @@ func BenchmarkName(b *testing.B) {
func BenchmarkReflect(b *testing.B) {
m := new(testpb.TestAllTypes).ProtoReflect()
fds := m.Descriptor().Fields()
- vs := make([]pref.Value, fds.Len())
+ vs := make([]protoreflect.Value, fds.Len())
for i := range vs {
vs[i] = m.NewField(fds.Get(i))
}
@@ -1598,7 +1598,7 @@ func BenchmarkReflect(b *testing.B) {
b.Run("Range", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
- m.Range(func(pref.FieldDescriptor, pref.Value) bool {
+ m.Range(func(protoreflect.FieldDescriptor, protoreflect.Value) bool {
return true
})
}
diff --git a/internal/impl/validate.go b/internal/impl/validate.go
index 08cfb605..a24e6bbd 100644
--- a/internal/impl/validate.go
+++ b/internal/impl/validate.go
@@ -16,9 +16,9 @@ import (
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/internal/genid"
"google.golang.org/protobuf/internal/strs"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- preg "google.golang.org/protobuf/reflect/protoregistry"
- piface "google.golang.org/protobuf/runtime/protoiface"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/runtime/protoiface"
)
// ValidationStatus is the result of validating the wire-format encoding of a message.
@@ -56,20 +56,20 @@ func (v ValidationStatus) String() string {
// of the message type.
//
// This function is exposed for testing.
-func Validate(mt pref.MessageType, in piface.UnmarshalInput) (out piface.UnmarshalOutput, _ ValidationStatus) {
+func Validate(mt protoreflect.MessageType, in protoiface.UnmarshalInput) (out protoiface.UnmarshalOutput, _ ValidationStatus) {
mi, ok := mt.(*MessageInfo)
if !ok {
return out, ValidationUnknown
}
if in.Resolver == nil {
- in.Resolver = preg.GlobalTypes
+ in.Resolver = protoregistry.GlobalTypes
}
o, st := mi.validate(in.Buf, 0, unmarshalOptions{
flags: in.Flags,
resolver: in.Resolver,
})
if o.initialized {
- out.Flags |= piface.UnmarshalInitialized
+ out.Flags |= protoiface.UnmarshalInitialized
}
return out, st
}
@@ -106,22 +106,22 @@ const (
validationTypeMessageSetItem
)
-func newFieldValidationInfo(mi *MessageInfo, si structInfo, fd pref.FieldDescriptor, ft reflect.Type) validationInfo {
+func newFieldValidationInfo(mi *MessageInfo, si structInfo, fd protoreflect.FieldDescriptor, ft reflect.Type) validationInfo {
var vi validationInfo
switch {
case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic():
switch fd.Kind() {
- case pref.MessageKind:
+ case protoreflect.MessageKind:
vi.typ = validationTypeMessage
if ot, ok := si.oneofWrappersByNumber[fd.Number()]; ok {
vi.mi = getMessageInfo(ot.Field(0).Type)
}
- case pref.GroupKind:
+ case protoreflect.GroupKind:
vi.typ = validationTypeGroup
if ot, ok := si.oneofWrappersByNumber[fd.Number()]; ok {
vi.mi = getMessageInfo(ot.Field(0).Type)
}
- case pref.StringKind:
+ case protoreflect.StringKind:
if strs.EnforceUTF8(fd) {
vi.typ = validationTypeUTF8String
}
@@ -129,7 +129,7 @@ func newFieldValidationInfo(mi *MessageInfo, si structInfo, fd pref.FieldDescrip
default:
vi = newValidationInfo(fd, ft)
}
- if fd.Cardinality() == pref.Required {
+ if fd.Cardinality() == protoreflect.Required {
// Avoid overflow. The required field check is done with a 64-bit mask, with
// any message containing more than 64 required fields always reported as
// potentially uninitialized, so it is not important to get a precise count
@@ -142,22 +142,22 @@ func newFieldValidationInfo(mi *MessageInfo, si structInfo, fd pref.FieldDescrip
return vi
}
-func newValidationInfo(fd pref.FieldDescriptor, ft reflect.Type) validationInfo {
+func newValidationInfo(fd protoreflect.FieldDescriptor, ft reflect.Type) validationInfo {
var vi validationInfo
switch {
case fd.IsList():
switch fd.Kind() {
- case pref.MessageKind:
+ case protoreflect.MessageKind:
vi.typ = validationTypeMessage
if ft.Kind() == reflect.Slice {
vi.mi = getMessageInfo(ft.Elem())
}
- case pref.GroupKind:
+ case protoreflect.GroupKind:
vi.typ = validationTypeGroup
if ft.Kind() == reflect.Slice {
vi.mi = getMessageInfo(ft.Elem())
}
- case pref.StringKind:
+ case protoreflect.StringKind:
vi.typ = validationTypeBytes
if strs.EnforceUTF8(fd) {
vi.typ = validationTypeUTF8String
@@ -175,33 +175,33 @@ func newValidationInfo(fd pref.FieldDescriptor, ft reflect.Type) validationInfo
case fd.IsMap():
vi.typ = validationTypeMap
switch fd.MapKey().Kind() {
- case pref.StringKind:
+ case protoreflect.StringKind:
if strs.EnforceUTF8(fd) {
vi.keyType = validationTypeUTF8String
}
}
switch fd.MapValue().Kind() {
- case pref.MessageKind:
+ case protoreflect.MessageKind:
vi.valType = validationTypeMessage
if ft.Kind() == reflect.Map {
vi.mi = getMessageInfo(ft.Elem())
}
- case pref.StringKind:
+ case protoreflect.StringKind:
if strs.EnforceUTF8(fd) {
vi.valType = validationTypeUTF8String
}
}
default:
switch fd.Kind() {
- case pref.MessageKind:
+ case protoreflect.MessageKind:
vi.typ = validationTypeMessage
if !fd.IsWeak() {
vi.mi = getMessageInfo(ft)
}
- case pref.GroupKind:
+ case protoreflect.GroupKind:
vi.typ = validationTypeGroup
vi.mi = getMessageInfo(ft)
- case pref.StringKind:
+ case protoreflect.StringKind:
vi.typ = validationTypeBytes
if strs.EnforceUTF8(fd) {
vi.typ = validationTypeUTF8String
@@ -314,11 +314,11 @@ State:
break
}
messageName := fd.Message().FullName()
- messageType, err := preg.GlobalTypes.FindMessageByName(messageName)
+ messageType, err := protoregistry.GlobalTypes.FindMessageByName(messageName)
switch err {
case nil:
vi.mi, _ = messageType.(*MessageInfo)
- case preg.NotFound:
+ case protoregistry.NotFound:
vi.typ = validationTypeBytes
default:
return out, ValidationUnknown
@@ -335,7 +335,7 @@ State:
// unmarshaling to begin failing. Supporting this requires some way to
// determine if the resolver is frozen.
xt, err := opts.resolver.FindExtensionByNumber(st.mi.Desc.FullName(), num)
- if err != nil && err != preg.NotFound {
+ if err != nil && err != protoregistry.NotFound {
return out, ValidationUnknown
}
if err == nil {
@@ -513,7 +513,7 @@ State:
}
xt, err := opts.resolver.FindExtensionByNumber(st.mi.Desc.FullName(), typeid)
switch {
- case err == preg.NotFound:
+ case err == protoregistry.NotFound:
b = b[n:]
case err != nil:
return out, ValidationUnknown
diff --git a/internal/impl/weak.go b/internal/impl/weak.go
index 009cbefd..eb79a7ba 100644
--- a/internal/impl/weak.go
+++ b/internal/impl/weak.go
@@ -7,7 +7,7 @@ package impl
import (
"fmt"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
)
@@ -17,32 +17,32 @@ import (
// defined directly on it.
type weakFields WeakFields
-func (w weakFields) get(num pref.FieldNumber) (pref.ProtoMessage, bool) {
+func (w weakFields) get(num protoreflect.FieldNumber) (protoreflect.ProtoMessage, bool) {
m, ok := w[int32(num)]
return m, ok
}
-func (w *weakFields) set(num pref.FieldNumber, m pref.ProtoMessage) {
+func (w *weakFields) set(num protoreflect.FieldNumber, m protoreflect.ProtoMessage) {
if *w == nil {
*w = make(weakFields)
}
(*w)[int32(num)] = m
}
-func (w *weakFields) clear(num pref.FieldNumber) {
+func (w *weakFields) clear(num protoreflect.FieldNumber) {
delete(*w, int32(num))
}
-func (Export) HasWeak(w WeakFields, num pref.FieldNumber) bool {
+func (Export) HasWeak(w WeakFields, num protoreflect.FieldNumber) bool {
_, ok := w[int32(num)]
return ok
}
-func (Export) ClearWeak(w *WeakFields, num pref.FieldNumber) {
+func (Export) ClearWeak(w *WeakFields, num protoreflect.FieldNumber) {
delete(*w, int32(num))
}
-func (Export) GetWeak(w WeakFields, num pref.FieldNumber, name pref.FullName) pref.ProtoMessage {
+func (Export) GetWeak(w WeakFields, num protoreflect.FieldNumber, name protoreflect.FullName) protoreflect.ProtoMessage {
if m, ok := w[int32(num)]; ok {
return m
}
@@ -53,7 +53,7 @@ func (Export) GetWeak(w WeakFields, num pref.FieldNumber, name pref.FullName) pr
return mt.Zero().Interface()
}
-func (Export) SetWeak(w *WeakFields, num pref.FieldNumber, name pref.FullName, m pref.ProtoMessage) {
+func (Export) SetWeak(w *WeakFields, num protoreflect.FieldNumber, name protoreflect.FullName, m protoreflect.ProtoMessage) {
if m != nil {
mt, _ := protoregistry.GlobalTypes.FindMessageByName(name)
if mt == nil {
diff --git a/internal/order/order.go b/internal/order/order.go
index 2a24953f..33745ed0 100644
--- a/internal/order/order.go
+++ b/internal/order/order.go
@@ -5,12 +5,12 @@
package order
import (
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
// FieldOrder specifies the ordering to visit message fields.
// It is a function that reports whether x is ordered before y.
-type FieldOrder func(x, y pref.FieldDescriptor) bool
+type FieldOrder func(x, y protoreflect.FieldDescriptor) bool
var (
// AnyFieldOrder specifies no specific field ordering.
@@ -18,9 +18,9 @@ var (
// LegacyFieldOrder sorts fields in the same ordering as emitted by
// wire serialization in the github.com/golang/protobuf implementation.
- LegacyFieldOrder FieldOrder = func(x, y pref.FieldDescriptor) bool {
+ LegacyFieldOrder FieldOrder = func(x, y protoreflect.FieldDescriptor) bool {
ox, oy := x.ContainingOneof(), y.ContainingOneof()
- inOneof := func(od pref.OneofDescriptor) bool {
+ inOneof := func(od protoreflect.OneofDescriptor) bool {
return od != nil && !od.IsSynthetic()
}
@@ -41,14 +41,14 @@ var (
}
// NumberFieldOrder sorts fields by their field number.
- NumberFieldOrder FieldOrder = func(x, y pref.FieldDescriptor) bool {
+ NumberFieldOrder FieldOrder = func(x, y protoreflect.FieldDescriptor) bool {
return x.Number() < y.Number()
}
// IndexNameFieldOrder sorts non-extension fields before extension fields.
// Non-extensions are sorted according to their declaration index.
// Extensions are sorted according to their full name.
- IndexNameFieldOrder FieldOrder = func(x, y pref.FieldDescriptor) bool {
+ IndexNameFieldOrder FieldOrder = func(x, y protoreflect.FieldDescriptor) bool {
// Non-extension fields sort before extension fields.
if x.IsExtension() != y.IsExtension() {
return !x.IsExtension() && y.IsExtension()
@@ -64,7 +64,7 @@ var (
// KeyOrder specifies the ordering to visit map entries.
// It is a function that reports whether x is ordered before y.
-type KeyOrder func(x, y pref.MapKey) bool
+type KeyOrder func(x, y protoreflect.MapKey) bool
var (
// AnyKeyOrder specifies no specific key ordering.
@@ -72,7 +72,7 @@ var (
// GenericKeyOrder sorts false before true, numeric keys in ascending order,
// and strings in lexicographical ordering according to UTF-8 codepoints.
- GenericKeyOrder KeyOrder = func(x, y pref.MapKey) bool {
+ GenericKeyOrder KeyOrder = func(x, y protoreflect.MapKey) bool {
switch x.Interface().(type) {
case bool:
return !x.Bool() && y.Bool()
diff --git a/internal/order/range.go b/internal/order/range.go
index fe5ffcf9..1665a68e 100644
--- a/internal/order/range.go
+++ b/internal/order/range.go
@@ -9,12 +9,12 @@ import (
"sort"
"sync"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
type messageField struct {
- fd pref.FieldDescriptor
- v pref.Value
+ fd protoreflect.FieldDescriptor
+ v protoreflect.Value
}
var messageFieldPool = sync.Pool{
@@ -26,7 +26,7 @@ type (
// The protoreflect.Message type implements this interface.
FieldRanger interface{ Range(VisitField) }
// VisitField is called every time a message field is visited.
- VisitField = func(pref.FieldDescriptor, pref.Value) bool
+ VisitField = func(protoreflect.FieldDescriptor, protoreflect.Value) bool
)
// RangeFields iterates over the fields of fs according to the specified order.
@@ -47,7 +47,7 @@ func RangeFields(fs FieldRanger, less FieldOrder, fn VisitField) {
}()
// Collect all fields in the message and sort them.
- fs.Range(func(fd pref.FieldDescriptor, v pref.Value) bool {
+ fs.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
fields = append(fields, messageField{fd, v})
return true
})
@@ -64,8 +64,8 @@ func RangeFields(fs FieldRanger, less FieldOrder, fn VisitField) {
}
type mapEntry struct {
- k pref.MapKey
- v pref.Value
+ k protoreflect.MapKey
+ v protoreflect.Value
}
var mapEntryPool = sync.Pool{
@@ -77,7 +77,7 @@ type (
// The protoreflect.Map type implements this interface.
EntryRanger interface{ Range(VisitEntry) }
// VisitEntry is called every time a map entry is visited.
- VisitEntry = func(pref.MapKey, pref.Value) bool
+ VisitEntry = func(protoreflect.MapKey, protoreflect.Value) bool
)
// RangeEntries iterates over the entries of es according to the specified order.
@@ -98,7 +98,7 @@ func RangeEntries(es EntryRanger, less KeyOrder, fn VisitEntry) {
}()
// Collect all entries in the map and sort them.
- es.Range(func(k pref.MapKey, v pref.Value) bool {
+ es.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool {
entries = append(entries, mapEntry{k, v})
return true
})
diff --git a/internal/protobuild/build.go b/internal/protobuild/build.go
index 46ab5c51..e432c3b6 100644
--- a/internal/protobuild/build.go
+++ b/internal/protobuild/build.go
@@ -13,7 +13,7 @@ import (
"math"
"reflect"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
)
@@ -33,25 +33,25 @@ type Value interface{}
// A Message is a template to apply to a message. Keys are field names, including
// extension names.
-type Message map[pref.Name]Value
+type Message map[protoreflect.Name]Value
// Unknown is a key associated with the unknown fields of a message.
// The value should be a []byte.
const Unknown = "@unknown"
// Build applies the template to a message.
-func (template Message) Build(m pref.Message) {
+func (template Message) Build(m protoreflect.Message) {
md := m.Descriptor()
fields := md.Fields()
- exts := make(map[pref.Name]pref.FieldDescriptor)
- protoregistry.GlobalTypes.RangeExtensionsByMessage(md.FullName(), func(xt pref.ExtensionType) bool {
+ exts := make(map[protoreflect.Name]protoreflect.FieldDescriptor)
+ protoregistry.GlobalTypes.RangeExtensionsByMessage(md.FullName(), func(xt protoreflect.ExtensionType) bool {
xd := xt.TypeDescriptor()
exts[xd.Name()] = xd
return true
})
for k, v := range template {
if k == Unknown {
- m.SetUnknown(pref.RawFields(v.([]byte)))
+ m.SetUnknown(protoreflect.RawFields(v.([]byte)))
continue
}
fd := fields.ByName(k)
@@ -101,50 +101,50 @@ func (template Message) Build(m pref.Message) {
}
}
-func fieldValue(fd pref.FieldDescriptor, v interface{}) pref.Value {
+func fieldValue(fd protoreflect.FieldDescriptor, v interface{}) protoreflect.Value {
switch o := v.(type) {
case int:
switch fd.Kind() {
- case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
if o < math.MinInt32 || math.MaxInt32 < o {
panic(fmt.Sprintf("%v: value %v out of range [%v, %v]", fd.FullName(), o, int32(math.MinInt32), int32(math.MaxInt32)))
}
v = int32(o)
- case pref.Uint32Kind, pref.Fixed32Kind:
+ case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
if o < 0 || math.MaxUint32 < 0 {
panic(fmt.Sprintf("%v: value %v out of range [%v, %v]", fd.FullName(), o, uint32(0), uint32(math.MaxUint32)))
}
v = uint32(o)
- case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
+ case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
v = int64(o)
- case pref.Uint64Kind, pref.Fixed64Kind:
+ case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
if o < 0 {
panic(fmt.Sprintf("%v: value %v out of range [%v, %v]", fd.FullName(), o, uint64(0), uint64(math.MaxUint64)))
}
v = uint64(o)
- case pref.FloatKind:
+ case protoreflect.FloatKind:
v = float32(o)
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
v = float64(o)
- case pref.EnumKind:
- v = pref.EnumNumber(o)
+ case protoreflect.EnumKind:
+ v = protoreflect.EnumNumber(o)
default:
panic(fmt.Sprintf("%v: invalid value type int", fd.FullName()))
}
case float64:
switch fd.Kind() {
- case pref.FloatKind:
+ case protoreflect.FloatKind:
v = float32(o)
}
case string:
switch fd.Kind() {
- case pref.BytesKind:
+ case protoreflect.BytesKind:
v = []byte(o)
- case pref.EnumKind:
- v = fd.Enum().Values().ByName(pref.Name(o)).Number()
+ case protoreflect.EnumKind:
+ v = fd.Enum().Values().ByName(protoreflect.Name(o)).Number()
}
case []byte:
- return pref.ValueOf(append([]byte{}, o...))
+ return protoreflect.ValueOf(append([]byte{}, o...))
}
- return pref.ValueOf(v)
+ return protoreflect.ValueOf(v)
}
diff --git a/internal/strs/strings_unsafe.go b/internal/strs/strings_unsafe.go
index 56a8a4ed..fea589c4 100644
--- a/internal/strs/strings_unsafe.go
+++ b/internal/strs/strings_unsafe.go
@@ -10,7 +10,7 @@ package strs
import (
"unsafe"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
type (
@@ -59,7 +59,7 @@ type Builder struct {
// AppendFullName is equivalent to protoreflect.FullName.Append,
// but optimized for large batches where each name has a shared lifetime.
-func (sb *Builder) AppendFullName(prefix pref.FullName, name pref.Name) pref.FullName {
+func (sb *Builder) AppendFullName(prefix protoreflect.FullName, name protoreflect.Name) protoreflect.FullName {
n := len(prefix) + len(".") + len(name)
if len(prefix) == 0 {
n -= len(".")
@@ -68,7 +68,7 @@ func (sb *Builder) AppendFullName(prefix pref.FullName, name pref.Name) pref.Ful
sb.buf = append(sb.buf, prefix...)
sb.buf = append(sb.buf, '.')
sb.buf = append(sb.buf, name...)
- return pref.FullName(sb.last(n))
+ return protoreflect.FullName(sb.last(n))
}
// MakeString is equivalent to string(b), but optimized for large batches
diff --git a/internal/testprotos/irregular/irregular.go b/internal/testprotos/irregular/irregular.go
index 48fbd167..7a6bd443 100644
--- a/internal/testprotos/irregular/irregular.go
+++ b/internal/testprotos/irregular/irregular.go
@@ -7,7 +7,7 @@ package irregular
import (
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/reflect/protodesc"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/runtime/protoiface"
"google.golang.org/protobuf/types/descriptorpb"
@@ -18,38 +18,38 @@ type IrregularMessage struct {
value string
}
-func (m *IrregularMessage) ProtoReflect() pref.Message { return (*message)(m) }
+func (m *IrregularMessage) ProtoReflect() protoreflect.Message { return (*message)(m) }
type message IrregularMessage
type messageType struct{}
-func (messageType) New() pref.Message { return &message{} }
-func (messageType) Zero() pref.Message { return (*message)(nil) }
-func (messageType) Descriptor() pref.MessageDescriptor { return fileDesc.Messages().Get(0) }
+func (messageType) New() protoreflect.Message { return &message{} }
+func (messageType) Zero() protoreflect.Message { return (*message)(nil) }
+func (messageType) Descriptor() protoreflect.MessageDescriptor { return fileDesc.Messages().Get(0) }
-func (m *message) New() pref.Message { return &message{} }
-func (m *message) Descriptor() pref.MessageDescriptor { return fileDesc.Messages().Get(0) }
-func (m *message) Type() pref.MessageType { return messageType{} }
-func (m *message) Interface() pref.ProtoMessage { return (*IrregularMessage)(m) }
-func (m *message) ProtoMethods() *protoiface.Methods { return nil }
+func (m *message) New() protoreflect.Message { return &message{} }
+func (m *message) Descriptor() protoreflect.MessageDescriptor { return fileDesc.Messages().Get(0) }
+func (m *message) Type() protoreflect.MessageType { return messageType{} }
+func (m *message) Interface() protoreflect.ProtoMessage { return (*IrregularMessage)(m) }
+func (m *message) ProtoMethods() *protoiface.Methods { return nil }
var fieldDescS = fileDesc.Messages().Get(0).Fields().Get(0)
-func (m *message) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
+func (m *message) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
if m.set {
- f(fieldDescS, pref.ValueOf(m.value))
+ f(fieldDescS, protoreflect.ValueOf(m.value))
}
}
-func (m *message) Has(fd pref.FieldDescriptor) bool {
+func (m *message) Has(fd protoreflect.FieldDescriptor) bool {
if fd == fieldDescS {
return m.set
}
panic("invalid field descriptor")
}
-func (m *message) Clear(fd pref.FieldDescriptor) {
+func (m *message) Clear(fd protoreflect.FieldDescriptor) {
if fd == fieldDescS {
m.value = ""
m.set = false
@@ -58,14 +58,14 @@ func (m *message) Clear(fd pref.FieldDescriptor) {
panic("invalid field descriptor")
}
-func (m *message) Get(fd pref.FieldDescriptor) pref.Value {
+func (m *message) Get(fd protoreflect.FieldDescriptor) protoreflect.Value {
if fd == fieldDescS {
- return pref.ValueOf(m.value)
+ return protoreflect.ValueOf(m.value)
}
panic("invalid field descriptor")
}
-func (m *message) Set(fd pref.FieldDescriptor, v pref.Value) {
+func (m *message) Set(fd protoreflect.FieldDescriptor, v protoreflect.Value) {
if fd == fieldDescS {
m.value = v.String()
m.set = true
@@ -74,26 +74,26 @@ func (m *message) Set(fd pref.FieldDescriptor, v pref.Value) {
panic("invalid field descriptor")
}
-func (m *message) Mutable(pref.FieldDescriptor) pref.Value {
+func (m *message) Mutable(protoreflect.FieldDescriptor) protoreflect.Value {
panic("invalid field descriptor")
}
-func (m *message) NewField(pref.FieldDescriptor) pref.Value {
+func (m *message) NewField(protoreflect.FieldDescriptor) protoreflect.Value {
panic("invalid field descriptor")
}
-func (m *message) WhichOneof(pref.OneofDescriptor) pref.FieldDescriptor {
+func (m *message) WhichOneof(protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
panic("invalid oneof descriptor")
}
-func (m *message) GetUnknown() pref.RawFields { return nil }
-func (m *message) SetUnknown(pref.RawFields) { return }
+func (m *message) GetUnknown() protoreflect.RawFields { return nil }
+func (m *message) SetUnknown(protoreflect.RawFields) { return }
func (m *message) IsValid() bool {
return m != nil
}
-var fileDesc = func() pref.FileDescriptor {
+var fileDesc = func() protoreflect.FileDescriptor {
p := &descriptorpb.FileDescriptorProto{}
if err := prototext.Unmarshal([]byte(descriptorText), p); err != nil {
panic(err)
diff --git a/proto/encode_test.go b/proto/encode_test.go
index 967def78..67ffce4f 100644
--- a/proto/encode_test.go
+++ b/proto/encode_test.go
@@ -16,7 +16,7 @@ import (
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/internal/errors"
orderpb "google.golang.org/protobuf/internal/testprotos/order"
@@ -202,7 +202,7 @@ func TestEncodeOrder(t *testing.T) {
proto.SetExtension(m, orderpb.E_Field_30, "thirty")
proto.SetExtension(m, orderpb.E_Field_31, "thirty-one")
proto.SetExtension(m, orderpb.E_Field_32, "thirty-two")
- want := []pref.FieldNumber{
+ want := []protoreflect.FieldNumber{
30, 31, 32, // extensions first, in number order
1, 2, 20, // non-extension, non-oneof in number order
10, // oneofs last, undefined order
@@ -214,7 +214,7 @@ func TestEncodeOrder(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- var got []pref.FieldNumber
+ var got []protoreflect.FieldNumber
for len(b) > 0 {
num, _, n := protowire.ConsumeField(b)
if n < 0 {
diff --git a/proto/equal.go b/proto/equal.go
index 4dba2b96..5017d540 100644
--- a/proto/equal.go
+++ b/proto/equal.go
@@ -10,7 +10,7 @@ import (
"reflect"
"google.golang.org/protobuf/encoding/protowire"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
// Equal reports whether two messages are equal.
@@ -42,14 +42,14 @@ func Equal(x, y Message) bool {
}
// equalMessage compares two messages.
-func equalMessage(mx, my pref.Message) bool {
+func equalMessage(mx, my protoreflect.Message) bool {
if mx.Descriptor() != my.Descriptor() {
return false
}
nx := 0
equal := true
- mx.Range(func(fd pref.FieldDescriptor, vx pref.Value) bool {
+ mx.Range(func(fd protoreflect.FieldDescriptor, vx protoreflect.Value) bool {
nx++
vy := my.Get(fd)
equal = my.Has(fd) && equalField(fd, vx, vy)
@@ -59,7 +59,7 @@ func equalMessage(mx, my pref.Message) bool {
return false
}
ny := 0
- my.Range(func(fd pref.FieldDescriptor, vx pref.Value) bool {
+ my.Range(func(fd protoreflect.FieldDescriptor, vx protoreflect.Value) bool {
ny++
return true
})
@@ -71,7 +71,7 @@ func equalMessage(mx, my pref.Message) bool {
}
// equalField compares two fields.
-func equalField(fd pref.FieldDescriptor, x, y pref.Value) bool {
+func equalField(fd protoreflect.FieldDescriptor, x, y protoreflect.Value) bool {
switch {
case fd.IsList():
return equalList(fd, x.List(), y.List())
@@ -83,12 +83,12 @@ func equalField(fd pref.FieldDescriptor, x, y pref.Value) bool {
}
// equalMap compares two maps.
-func equalMap(fd pref.FieldDescriptor, x, y pref.Map) bool {
+func equalMap(fd protoreflect.FieldDescriptor, x, y protoreflect.Map) bool {
if x.Len() != y.Len() {
return false
}
equal := true
- x.Range(func(k pref.MapKey, vx pref.Value) bool {
+ x.Range(func(k protoreflect.MapKey, vx protoreflect.Value) bool {
vy := y.Get(k)
equal = y.Has(k) && equalValue(fd.MapValue(), vx, vy)
return equal
@@ -97,7 +97,7 @@ func equalMap(fd pref.FieldDescriptor, x, y pref.Map) bool {
}
// equalList compares two lists.
-func equalList(fd pref.FieldDescriptor, x, y pref.List) bool {
+func equalList(fd protoreflect.FieldDescriptor, x, y protoreflect.List) bool {
if x.Len() != y.Len() {
return false
}
@@ -110,31 +110,31 @@ func equalList(fd pref.FieldDescriptor, x, y pref.List) bool {
}
// equalValue compares two singular values.
-func equalValue(fd pref.FieldDescriptor, x, y pref.Value) bool {
+func equalValue(fd protoreflect.FieldDescriptor, x, y protoreflect.Value) bool {
switch fd.Kind() {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
return x.Bool() == y.Bool()
- case pref.EnumKind:
+ case protoreflect.EnumKind:
return x.Enum() == y.Enum()
- case pref.Int32Kind, pref.Sint32Kind,
- pref.Int64Kind, pref.Sint64Kind,
- pref.Sfixed32Kind, pref.Sfixed64Kind:
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind,
+ protoreflect.Int64Kind, protoreflect.Sint64Kind,
+ protoreflect.Sfixed32Kind, protoreflect.Sfixed64Kind:
return x.Int() == y.Int()
- case pref.Uint32Kind, pref.Uint64Kind,
- pref.Fixed32Kind, pref.Fixed64Kind:
+ case protoreflect.Uint32Kind, protoreflect.Uint64Kind,
+ protoreflect.Fixed32Kind, protoreflect.Fixed64Kind:
return x.Uint() == y.Uint()
- case pref.FloatKind, pref.DoubleKind:
+ case protoreflect.FloatKind, protoreflect.DoubleKind:
fx := x.Float()
fy := y.Float()
if math.IsNaN(fx) || math.IsNaN(fy) {
return math.IsNaN(fx) && math.IsNaN(fy)
}
return fx == fy
- case pref.StringKind:
+ case protoreflect.StringKind:
return x.String() == y.String()
- case pref.BytesKind:
+ case protoreflect.BytesKind:
return bytes.Equal(x.Bytes(), y.Bytes())
- case pref.MessageKind, pref.GroupKind:
+ case protoreflect.MessageKind, protoreflect.GroupKind:
return equalMessage(x.Message(), y.Message())
default:
return x.Interface() == y.Interface()
@@ -143,7 +143,7 @@ func equalValue(fd pref.FieldDescriptor, x, y pref.Value) bool {
// equalUnknown compares unknown fields by direct comparison on the raw bytes
// of each individual field number.
-func equalUnknown(x, y pref.RawFields) bool {
+func equalUnknown(x, y protoreflect.RawFields) bool {
if len(x) != len(y) {
return false
}
@@ -151,8 +151,8 @@ func equalUnknown(x, y pref.RawFields) bool {
return true
}
- mx := make(map[pref.FieldNumber]pref.RawFields)
- my := make(map[pref.FieldNumber]pref.RawFields)
+ mx := make(map[protoreflect.FieldNumber]protoreflect.RawFields)
+ my := make(map[protoreflect.FieldNumber]protoreflect.RawFields)
for len(x) > 0 {
fnum, _, n := protowire.ConsumeField(x)
mx[fnum] = append(mx[fnum], x[:n]...)
diff --git a/reflect/protoregistry/registry_test.go b/reflect/protoregistry/registry_test.go
index d058c196..8baf12f0 100644
--- a/reflect/protoregistry/registry_test.go
+++ b/reflect/protoregistry/registry_test.go
@@ -14,20 +14,20 @@ import (
"google.golang.org/protobuf/encoding/prototext"
pimpl "google.golang.org/protobuf/internal/impl"
- pdesc "google.golang.org/protobuf/reflect/protodesc"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protodesc"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoregistry"
testpb "google.golang.org/protobuf/internal/testprotos/registry"
"google.golang.org/protobuf/types/descriptorpb"
)
-func mustMakeFile(s string) pref.FileDescriptor {
+func mustMakeFile(s string) protoreflect.FileDescriptor {
pb := new(descriptorpb.FileDescriptorProto)
if err := prototext.Unmarshal([]byte(s), pb); err != nil {
panic(err)
}
- fd, err := pdesc.NewFile(pb, nil)
+ fd, err := protodesc.NewFile(pb, nil)
if err != nil {
panic(err)
}
@@ -38,18 +38,18 @@ func TestFiles(t *testing.T) {
type (
file struct {
Path string
- Pkg pref.FullName
+ Pkg protoreflect.FullName
}
testFile struct {
- inFile pref.FileDescriptor
+ inFile protoreflect.FileDescriptor
wantErr string
}
testFindDesc struct {
- inName pref.FullName
+ inName protoreflect.FullName
wantFound bool
}
testRangePkg struct {
- inPkg pref.FullName
+ inPkg protoreflect.FullName
wantFiles []file
}
testFindPath struct {
@@ -282,7 +282,7 @@ func TestFiles(t *testing.T) {
})
for _, tt := range tests {
t.Run("", func(t *testing.T) {
- var files preg.Files
+ var files protoregistry.Files
for i, tc := range tt.files {
gotErr := files.RegisterFile(tc.inFile)
if ((gotErr == nil) != (tc.wantErr == "")) || !strings.Contains(fmt.Sprint(gotErr), tc.wantErr) {
@@ -302,7 +302,7 @@ func TestFiles(t *testing.T) {
var gotFiles []file
var gotCnt int
wantCnt := files.NumFilesByPackage(tc.inPkg)
- files.RangeFilesByPackage(tc.inPkg, func(fd pref.FileDescriptor) bool {
+ files.RangeFilesByPackage(tc.inPkg, func(fd protoreflect.FileDescriptor) bool {
gotFiles = append(gotFiles, file{fd.Path(), fd.Package()})
gotCnt++
return true
@@ -337,7 +337,7 @@ func TestTypes(t *testing.T) {
et1 := pimpl.Export{}.EnumTypeOf(testpb.Enum1_ONE)
xt1 := testpb.E_StringField
xt2 := testpb.E_Message4_MessageField
- registry := new(preg.Types)
+ registry := new(protoregistry.Types)
if err := registry.RegisterMessage(mt1); err != nil {
t.Fatalf("registry.RegisterMessage(%v) returns unexpected error: %v", mt1.Descriptor().FullName(), err)
}
@@ -354,7 +354,7 @@ func TestTypes(t *testing.T) {
t.Run("FindMessageByName", func(t *testing.T) {
tests := []struct {
name string
- messageType pref.MessageType
+ messageType protoreflect.MessageType
wantErr bool
wantNotFound bool
}{{
@@ -375,13 +375,13 @@ func TestTypes(t *testing.T) {
wantErr: true,
}}
for _, tc := range tests {
- got, err := registry.FindMessageByName(pref.FullName(tc.name))
+ got, err := registry.FindMessageByName(protoreflect.FullName(tc.name))
gotErr := err != nil
if gotErr != tc.wantErr {
t.Errorf("FindMessageByName(%v) = (_, %v), want error? %t", tc.name, err, tc.wantErr)
continue
}
- if tc.wantNotFound && err != preg.NotFound {
+ if tc.wantNotFound && err != protoregistry.NotFound {
t.Errorf("FindMessageByName(%v) got error: %v, want NotFound error", tc.name, err)
continue
}
@@ -394,7 +394,7 @@ func TestTypes(t *testing.T) {
t.Run("FindMessageByURL", func(t *testing.T) {
tests := []struct {
name string
- messageType pref.MessageType
+ messageType protoreflect.MessageType
wantErr bool
wantNotFound bool
}{{
@@ -415,7 +415,7 @@ func TestTypes(t *testing.T) {
t.Errorf("FindMessageByURL(%v) = (_, %v), want error? %t", tc.name, err, tc.wantErr)
continue
}
- if tc.wantNotFound && err != preg.NotFound {
+ if tc.wantNotFound && err != protoregistry.NotFound {
t.Errorf("FindMessageByURL(%v) got error: %v, want NotFound error", tc.name, err)
continue
}
@@ -428,7 +428,7 @@ func TestTypes(t *testing.T) {
t.Run("FindEnumByName", func(t *testing.T) {
tests := []struct {
name string
- enumType pref.EnumType
+ enumType protoreflect.EnumType
wantErr bool
wantNotFound bool
}{{
@@ -443,13 +443,13 @@ func TestTypes(t *testing.T) {
wantErr: true,
}}
for _, tc := range tests {
- got, err := registry.FindEnumByName(pref.FullName(tc.name))
+ got, err := registry.FindEnumByName(protoreflect.FullName(tc.name))
gotErr := err != nil
if gotErr != tc.wantErr {
t.Errorf("FindEnumByName(%v) = (_, %v), want error? %t", tc.name, err, tc.wantErr)
continue
}
- if tc.wantNotFound && err != preg.NotFound {
+ if tc.wantNotFound && err != protoregistry.NotFound {
t.Errorf("FindEnumByName(%v) got error: %v, want NotFound error", tc.name, err)
continue
}
@@ -462,7 +462,7 @@ func TestTypes(t *testing.T) {
t.Run("FindExtensionByName", func(t *testing.T) {
tests := []struct {
name string
- extensionType pref.ExtensionType
+ extensionType protoreflect.ExtensionType
wantErr bool
wantNotFound bool
}{{
@@ -480,13 +480,13 @@ func TestTypes(t *testing.T) {
wantErr: true,
}}
for _, tc := range tests {
- got, err := registry.FindExtensionByName(pref.FullName(tc.name))
+ got, err := registry.FindExtensionByName(protoreflect.FullName(tc.name))
gotErr := err != nil
if gotErr != tc.wantErr {
t.Errorf("FindExtensionByName(%v) = (_, %v), want error? %t", tc.name, err, tc.wantErr)
continue
}
- if tc.wantNotFound && err != preg.NotFound {
+ if tc.wantNotFound && err != protoregistry.NotFound {
t.Errorf("FindExtensionByName(%v) got error: %v, want NotFound error", tc.name, err)
continue
}
@@ -500,7 +500,7 @@ func TestTypes(t *testing.T) {
tests := []struct {
parent string
number int32
- extensionType pref.ExtensionType
+ extensionType protoreflect.ExtensionType
wantErr bool
wantNotFound bool
}{{
@@ -538,13 +538,13 @@ func TestTypes(t *testing.T) {
wantNotFound: true,
}}
for _, tc := range tests {
- got, err := registry.FindExtensionByNumber(pref.FullName(tc.parent), pref.FieldNumber(tc.number))
+ got, err := registry.FindExtensionByNumber(protoreflect.FullName(tc.parent), protoreflect.FieldNumber(tc.number))
gotErr := err != nil
if gotErr != tc.wantErr {
t.Errorf("FindExtensionByNumber(%v, %d) = (_, %v), want error? %t", tc.parent, tc.number, err, tc.wantErr)
continue
}
- if tc.wantNotFound && err != preg.NotFound {
+ if tc.wantNotFound && err != protoregistry.NotFound {
t.Errorf("FindExtensionByNumber(%v, %d) got error %v, want NotFound error", tc.parent, tc.number, err)
continue
}
@@ -555,34 +555,34 @@ func TestTypes(t *testing.T) {
})
sortTypes := cmp.Options{
- cmpopts.SortSlices(func(x, y pref.EnumType) bool {
+ cmpopts.SortSlices(func(x, y protoreflect.EnumType) bool {
return x.Descriptor().FullName() < y.Descriptor().FullName()
}),
- cmpopts.SortSlices(func(x, y pref.MessageType) bool {
+ cmpopts.SortSlices(func(x, y protoreflect.MessageType) bool {
return x.Descriptor().FullName() < y.Descriptor().FullName()
}),
- cmpopts.SortSlices(func(x, y pref.ExtensionType) bool {
+ cmpopts.SortSlices(func(x, y protoreflect.ExtensionType) bool {
return x.TypeDescriptor().FullName() < y.TypeDescriptor().FullName()
}),
}
compare := cmp.Options{
- cmp.Comparer(func(x, y pref.EnumType) bool {
+ cmp.Comparer(func(x, y protoreflect.EnumType) bool {
return x == y
}),
- cmp.Comparer(func(x, y pref.ExtensionType) bool {
+ cmp.Comparer(func(x, y protoreflect.ExtensionType) bool {
return x == y
}),
- cmp.Comparer(func(x, y pref.MessageType) bool {
+ cmp.Comparer(func(x, y protoreflect.MessageType) bool {
return x == y
}),
}
t.Run("RangeEnums", func(t *testing.T) {
- want := []pref.EnumType{et1}
- var got []pref.EnumType
+ want := []protoreflect.EnumType{et1}
+ var got []protoreflect.EnumType
var gotCnt int
wantCnt := registry.NumEnums()
- registry.RangeEnums(func(et pref.EnumType) bool {
+ registry.RangeEnums(func(et protoreflect.EnumType) bool {
got = append(got, et)
gotCnt++
return true
@@ -597,11 +597,11 @@ func TestTypes(t *testing.T) {
})
t.Run("RangeMessages", func(t *testing.T) {
- want := []pref.MessageType{mt1}
- var got []pref.MessageType
+ want := []protoreflect.MessageType{mt1}
+ var got []protoreflect.MessageType
var gotCnt int
wantCnt := registry.NumMessages()
- registry.RangeMessages(func(mt pref.MessageType) bool {
+ registry.RangeMessages(func(mt protoreflect.MessageType) bool {
got = append(got, mt)
gotCnt++
return true
@@ -616,11 +616,11 @@ func TestTypes(t *testing.T) {
})
t.Run("RangeExtensions", func(t *testing.T) {
- want := []pref.ExtensionType{xt1, xt2}
- var got []pref.ExtensionType
+ want := []protoreflect.ExtensionType{xt1, xt2}
+ var got []protoreflect.ExtensionType
var gotCnt int
wantCnt := registry.NumExtensions()
- registry.RangeExtensions(func(xt pref.ExtensionType) bool {
+ registry.RangeExtensions(func(xt protoreflect.ExtensionType) bool {
got = append(got, xt)
gotCnt++
return true
@@ -635,11 +635,11 @@ func TestTypes(t *testing.T) {
})
t.Run("RangeExtensionsByMessage", func(t *testing.T) {
- want := []pref.ExtensionType{xt1, xt2}
- var got []pref.ExtensionType
+ want := []protoreflect.ExtensionType{xt1, xt2}
+ var got []protoreflect.ExtensionType
var gotCnt int
wantCnt := registry.NumExtensionsByMessage("testprotos.Message1")
- registry.RangeExtensionsByMessage("testprotos.Message1", func(xt pref.ExtensionType) bool {
+ registry.RangeExtensionsByMessage("testprotos.Message1", func(xt protoreflect.ExtensionType) bool {
got = append(got, xt)
gotCnt++
return true
diff --git a/testing/prototest/enum.go b/testing/prototest/enum.go
index 9ee422e5..db9dacd4 100644
--- a/testing/prototest/enum.go
+++ b/testing/prototest/enum.go
@@ -7,13 +7,13 @@ package prototest
import (
"testing"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
// Enum tests an EnumType implementation.
type Enum struct{}
-func (test Enum) Test(t testing.TB, et pref.EnumType) {
+func (test Enum) Test(t testing.TB, et protoreflect.EnumType) {
ed := et.Descriptor()
values := ed.Values()
for i := 0; i < values.Len(); i++ {
diff --git a/types/dynamicpb/dynamic.go b/types/dynamicpb/dynamic.go
index 900b9d28..f77ef0de 100644
--- a/types/dynamicpb/dynamic.go
+++ b/types/dynamicpb/dynamic.go
@@ -9,24 +9,24 @@ import (
"math"
"google.golang.org/protobuf/internal/errors"
- pref "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/runtime/protoiface"
"google.golang.org/protobuf/runtime/protoimpl"
)
// enum is a dynamic protoreflect.Enum.
type enum struct {
- num pref.EnumNumber
- typ pref.EnumType
+ num protoreflect.EnumNumber
+ typ protoreflect.EnumType
}
-func (e enum) Descriptor() pref.EnumDescriptor { return e.typ.Descriptor() }
-func (e enum) Type() pref.EnumType { return e.typ }
-func (e enum) Number() pref.EnumNumber { return e.num }
+func (e enum) Descriptor() protoreflect.EnumDescriptor { return e.typ.Descriptor() }
+func (e enum) Type() protoreflect.EnumType { return e.typ }
+func (e enum) Number() protoreflect.EnumNumber { return e.num }
// enumType is a dynamic protoreflect.EnumType.
type enumType struct {
- desc pref.EnumDescriptor
+ desc protoreflect.EnumDescriptor
}
// NewEnumType creates a new EnumType with the provided descriptor.
@@ -35,12 +35,12 @@ type enumType struct {
// That is, if ed1 == ed2, then NewEnumType(ed1) == NewEnumType(ed2).
//
// Enum values created by the EnumType are equal if their numbers are equal.
-func NewEnumType(desc pref.EnumDescriptor) pref.EnumType {
+func NewEnumType(desc protoreflect.EnumDescriptor) protoreflect.EnumType {
return enumType{desc}
}
-func (et enumType) New(n pref.EnumNumber) pref.Enum { return enum{n, et} }
-func (et enumType) Descriptor() pref.EnumDescriptor { return et.desc }
+func (et enumType) New(n protoreflect.EnumNumber) protoreflect.Enum { return enum{n, et} }
+func (et enumType) Descriptor() protoreflect.EnumDescriptor { return et.desc }
// extensionType is a dynamic protoreflect.ExtensionType.
type extensionType struct {
@@ -64,23 +64,23 @@ type extensionType struct {
// Operations which modify a Message are not safe for concurrent use.
type Message struct {
typ messageType
- known map[pref.FieldNumber]pref.Value
- ext map[pref.FieldNumber]pref.FieldDescriptor
- unknown pref.RawFields
+ known map[protoreflect.FieldNumber]protoreflect.Value
+ ext map[protoreflect.FieldNumber]protoreflect.FieldDescriptor
+ unknown protoreflect.RawFields
}
var (
- _ pref.Message = (*Message)(nil)
- _ pref.ProtoMessage = (*Message)(nil)
- _ protoiface.MessageV1 = (*Message)(nil)
+ _ protoreflect.Message = (*Message)(nil)
+ _ protoreflect.ProtoMessage = (*Message)(nil)
+ _ protoiface.MessageV1 = (*Message)(nil)
)
// NewMessage creates a new message with the provided descriptor.
-func NewMessage(desc pref.MessageDescriptor) *Message {
+func NewMessage(desc protoreflect.MessageDescriptor) *Message {
return &Message{
typ: messageType{desc},
- known: make(map[pref.FieldNumber]pref.Value),
- ext: make(map[pref.FieldNumber]pref.FieldDescriptor),
+ known: make(map[protoreflect.FieldNumber]protoreflect.Value),
+ ext: make(map[protoreflect.FieldNumber]protoreflect.FieldDescriptor),
}
}
@@ -88,7 +88,7 @@ func NewMessage(desc pref.MessageDescriptor) *Message {
func (m *Message) ProtoMessage() {}
// ProtoReflect implements the protoreflect.ProtoMessage interface.
-func (m *Message) ProtoReflect() pref.Message {
+func (m *Message) ProtoReflect() protoreflect.Message {
return m
}
@@ -99,30 +99,30 @@ func (m *Message) String() string {
// Reset clears the message to be empty, but preserves the dynamic message type.
func (m *Message) Reset() {
- m.known = make(map[pref.FieldNumber]pref.Value)
- m.ext = make(map[pref.FieldNumber]pref.FieldDescriptor)
+ m.known = make(map[protoreflect.FieldNumber]protoreflect.Value)
+ m.ext = make(map[protoreflect.FieldNumber]protoreflect.FieldDescriptor)
m.unknown = nil
}
// Descriptor returns the message descriptor.
-func (m *Message) Descriptor() pref.MessageDescriptor {
+func (m *Message) Descriptor() protoreflect.MessageDescriptor {
return m.typ.desc
}
// Type returns the message type.
-func (m *Message) Type() pref.MessageType {
+func (m *Message) Type() protoreflect.MessageType {
return m.typ
}
// New returns a newly allocated empty message with the same descriptor.
// See protoreflect.Message for details.
-func (m *Message) New() pref.Message {
+func (m *Message) New() protoreflect.Message {
return m.Type().New()
}
// Interface returns the message.
// See protoreflect.Message for details.
-func (m *Message) Interface() pref.ProtoMessage {
+func (m *Message) Interface() protoreflect.ProtoMessage {
return m
}
@@ -134,7 +134,7 @@ func (m *Message) ProtoMethods() *protoiface.Methods {
// Range visits every populated field in undefined order.
// See protoreflect.Message for details.
-func (m *Message) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
+func (m *Message) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
for num, v := range m.known {
fd := m.ext[num]
if fd == nil {
@@ -151,7 +151,7 @@ func (m *Message) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
// Has reports whether a field is populated.
// See protoreflect.Message for details.
-func (m *Message) Has(fd pref.FieldDescriptor) bool {
+func (m *Message) Has(fd protoreflect.FieldDescriptor) bool {
m.checkField(fd)
if fd.IsExtension() && m.ext[fd.Number()] != fd {
return false
@@ -165,7 +165,7 @@ func (m *Message) Has(fd pref.FieldDescriptor) bool {
// Clear clears a field.
// See protoreflect.Message for details.
-func (m *Message) Clear(fd pref.FieldDescriptor) {
+func (m *Message) Clear(fd protoreflect.FieldDescriptor) {
m.checkField(fd)
num := fd.Number()
delete(m.known, num)
@@ -174,12 +174,12 @@ func (m *Message) Clear(fd pref.FieldDescriptor) {
// Get returns the value of a field.
// See protoreflect.Message for details.
-func (m *Message) Get(fd pref.FieldDescriptor) pref.Value {
+func (m *Message) Get(fd protoreflect.FieldDescriptor) protoreflect.Value {
m.checkField(fd)
num := fd.Number()
if fd.IsExtension() {
if fd != m.ext[num] {
- return fd.(pref.ExtensionTypeDescriptor).Type().Zero()
+ return fd.(protoreflect.ExtensionTypeDescriptor).Type().Zero()
}
return m.known[num]
}
@@ -199,13 +199,13 @@ func (m *Message) Get(fd pref.FieldDescriptor) pref.Value {
}
switch {
case fd.IsMap():
- return pref.ValueOfMap(&dynamicMap{desc: fd})
+ return protoreflect.ValueOfMap(&dynamicMap{desc: fd})
case fd.IsList():
- return pref.ValueOfList(emptyList{desc: fd})
+ return protoreflect.ValueOfList(emptyList{desc: fd})
case fd.Message() != nil:
- return pref.ValueOfMessage(&Message{typ: messageType{fd.Message()}})
- case fd.Kind() == pref.BytesKind:
- return pref.ValueOfBytes(append([]byte(nil), fd.Default().Bytes()...))
+ return protoreflect.ValueOfMessage(&Message{typ: messageType{fd.Message()}})
+ case fd.Kind() == protoreflect.BytesKind:
+ return protoreflect.ValueOfBytes(append([]byte(nil), fd.Default().Bytes()...))
default:
return fd.Default()
}
@@ -213,7 +213,7 @@ func (m *Message) Get(fd pref.FieldDescriptor) pref.Value {
// Mutable returns a mutable reference to a repeated, map, or message field.
// See protoreflect.Message for details.
-func (m *Message) Mutable(fd pref.FieldDescriptor) pref.Value {
+func (m *Message) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
m.checkField(fd)
if !fd.IsMap() && !fd.IsList() && fd.Message() == nil {
panic(errors.New("%v: getting mutable reference to non-composite type", fd.FullName()))
@@ -225,7 +225,7 @@ func (m *Message) Mutable(fd pref.FieldDescriptor) pref.Value {
if fd.IsExtension() {
if fd != m.ext[num] {
m.ext[num] = fd
- m.known[num] = fd.(pref.ExtensionTypeDescriptor).Type().New()
+ m.known[num] = fd.(protoreflect.ExtensionTypeDescriptor).Type().New()
}
return m.known[num]
}
@@ -242,7 +242,7 @@ func (m *Message) Mutable(fd pref.FieldDescriptor) pref.Value {
// Set stores a value in a field.
// See protoreflect.Message for details.
-func (m *Message) Set(fd pref.FieldDescriptor, v pref.Value) {
+func (m *Message) Set(fd protoreflect.FieldDescriptor, v protoreflect.Value) {
m.checkField(fd)
if m.known == nil {
panic(errors.New("%v: modification of read-only message", fd.FullName()))
@@ -250,7 +250,7 @@ func (m *Message) Set(fd pref.FieldDescriptor, v pref.Value) {
if fd.IsExtension() {
isValid := true
switch {
- case !fd.(pref.ExtensionTypeDescriptor).Type().IsValidValue(v):
+ case !fd.(protoreflect.ExtensionTypeDescriptor).Type().IsValidValue(v):
isValid = false
case fd.IsList():
isValid = v.List().IsValid()
@@ -270,7 +270,7 @@ func (m *Message) Set(fd pref.FieldDescriptor, v pref.Value) {
m.known[fd.Number()] = v
}
-func (m *Message) clearOtherOneofFields(fd pref.FieldDescriptor) {
+func (m *Message) clearOtherOneofFields(fd protoreflect.FieldDescriptor) {
od := fd.ContainingOneof()
if od == nil {
return
@@ -285,20 +285,20 @@ func (m *Message) clearOtherOneofFields(fd pref.FieldDescriptor) {
// NewField returns a new value for assignable to the field of a given descriptor.
// See protoreflect.Message for details.
-func (m *Message) NewField(fd pref.FieldDescriptor) pref.Value {
+func (m *Message) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value {
m.checkField(fd)
switch {
case fd.IsExtension():
- return fd.(pref.ExtensionTypeDescriptor).Type().New()
+ return fd.(protoreflect.ExtensionTypeDescriptor).Type().New()
case fd.IsMap():
- return pref.ValueOfMap(&dynamicMap{
+ return protoreflect.ValueOfMap(&dynamicMap{
desc: fd,
- mapv: make(map[interface{}]pref.Value),
+ mapv: make(map[interface{}]protoreflect.Value),
})
case fd.IsList():
- return pref.ValueOfList(&dynamicList{desc: fd})
+ return protoreflect.ValueOfList(&dynamicList{desc: fd})
case fd.Message() != nil:
- return pref.ValueOfMessage(NewMessage(fd.Message()).ProtoReflect())
+ return protoreflect.ValueOfMessage(NewMessage(fd.Message()).ProtoReflect())
default:
return fd.Default()
}
@@ -306,7 +306,7 @@ func (m *Message) NewField(fd pref.FieldDescriptor) pref.Value {
// WhichOneof reports which field in a oneof is populated, returning nil if none are populated.
// See protoreflect.Message for details.
-func (m *Message) WhichOneof(od pref.OneofDescriptor) pref.FieldDescriptor {
+func (m *Message) WhichOneof(od protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
for i := 0; i < od.Fields().Len(); i++ {
fd := od.Fields().Get(i)
if m.Has(fd) {
@@ -318,13 +318,13 @@ func (m *Message) WhichOneof(od pref.OneofDescriptor) pref.FieldDescriptor {
// GetUnknown returns the raw unknown fields.
// See protoreflect.Message for details.
-func (m *Message) GetUnknown() pref.RawFields {
+func (m *Message) GetUnknown() protoreflect.RawFields {
return m.unknown
}
// SetUnknown sets the raw unknown fields.
// See protoreflect.Message for details.
-func (m *Message) SetUnknown(r pref.RawFields) {
+func (m *Message) SetUnknown(r protoreflect.RawFields) {
if m.known == nil {
panic(errors.New("%v: modification of read-only message", m.typ.desc.FullName()))
}
@@ -337,9 +337,9 @@ func (m *Message) IsValid() bool {
return m.known != nil
}
-func (m *Message) checkField(fd pref.FieldDescriptor) {
+func (m *Message) checkField(fd protoreflect.FieldDescriptor) {
if fd.IsExtension() && fd.ContainingMessage().FullName() == m.Descriptor().FullName() {
- if _, ok := fd.(pref.ExtensionTypeDescriptor); !ok {
+ if _, ok := fd.(protoreflect.ExtensionTypeDescriptor); !ok {
panic(errors.New("%v: extension field descriptor does not implement ExtensionTypeDescriptor", fd.FullName()))
}
return
@@ -355,27 +355,27 @@ func (m *Message) checkField(fd pref.FieldDescriptor) {
}
type messageType struct {
- desc pref.MessageDescriptor
+ desc protoreflect.MessageDescriptor
}
// NewMessageType creates a new MessageType with the provided descriptor.
//
// MessageTypes created by this package are equal if their descriptors are equal.
// That is, if md1 == md2, then NewMessageType(md1) == NewMessageType(md2).
-func NewMessageType(desc pref.MessageDescriptor) pref.MessageType {
+func NewMessageType(desc protoreflect.MessageDescriptor) protoreflect.MessageType {
return messageType{desc}
}
-func (mt messageType) New() pref.Message { return NewMessage(mt.desc) }
-func (mt messageType) Zero() pref.Message { return &Message{typ: messageType{mt.desc}} }
-func (mt messageType) Descriptor() pref.MessageDescriptor { return mt.desc }
-func (mt messageType) Enum(i int) pref.EnumType {
+func (mt messageType) New() protoreflect.Message { return NewMessage(mt.desc) }
+func (mt messageType) Zero() protoreflect.Message { return &Message{typ: messageType{mt.desc}} }
+func (mt messageType) Descriptor() protoreflect.MessageDescriptor { return mt.desc }
+func (mt messageType) Enum(i int) protoreflect.EnumType {
if ed := mt.desc.Fields().Get(i).Enum(); ed != nil {
return NewEnumType(ed)
}
return nil
}
-func (mt messageType) Message(i int) pref.MessageType {
+func (mt messageType) Message(i int) protoreflect.MessageType {
if md := mt.desc.Fields().Get(i).Message(); md != nil {
return NewMessageType(md)
}
@@ -383,42 +383,46 @@ func (mt messageType) Message(i int) pref.MessageType {
}
type emptyList struct {
- desc pref.FieldDescriptor
+ desc protoreflect.FieldDescriptor
}
-func (x emptyList) Len() int { return 0 }
-func (x emptyList) Get(n int) pref.Value { panic(errors.New("out of range")) }
-func (x emptyList) Set(n int, v pref.Value) { panic(errors.New("modification of immutable list")) }
-func (x emptyList) Append(v pref.Value) { panic(errors.New("modification of immutable list")) }
-func (x emptyList) AppendMutable() pref.Value { panic(errors.New("modification of immutable list")) }
-func (x emptyList) Truncate(n int) { panic(errors.New("modification of immutable list")) }
-func (x emptyList) NewElement() pref.Value { return newListEntry(x.desc) }
-func (x emptyList) IsValid() bool { return false }
+func (x emptyList) Len() int { return 0 }
+func (x emptyList) Get(n int) protoreflect.Value { panic(errors.New("out of range")) }
+func (x emptyList) Set(n int, v protoreflect.Value) {
+ panic(errors.New("modification of immutable list"))
+}
+func (x emptyList) Append(v protoreflect.Value) { panic(errors.New("modification of immutable list")) }
+func (x emptyList) AppendMutable() protoreflect.Value {
+ panic(errors.New("modification of immutable list"))
+}
+func (x emptyList) Truncate(n int) { panic(errors.New("modification of immutable list")) }
+func (x emptyList) NewElement() protoreflect.Value { return newListEntry(x.desc) }
+func (x emptyList) IsValid() bool { return false }
type dynamicList struct {
- desc pref.FieldDescriptor
- list []pref.Value
+ desc protoreflect.FieldDescriptor
+ list []protoreflect.Value
}
func (x *dynamicList) Len() int {
return len(x.list)
}
-func (x *dynamicList) Get(n int) pref.Value {
+func (x *dynamicList) Get(n int) protoreflect.Value {
return x.list[n]
}
-func (x *dynamicList) Set(n int, v pref.Value) {
+func (x *dynamicList) Set(n int, v protoreflect.Value) {
typecheckSingular(x.desc, v)
x.list[n] = v
}
-func (x *dynamicList) Append(v pref.Value) {
+func (x *dynamicList) Append(v protoreflect.Value) {
typecheckSingular(x.desc, v)
x.list = append(x.list, v)
}
-func (x *dynamicList) AppendMutable() pref.Value {
+func (x *dynamicList) AppendMutable() protoreflect.Value {
if x.desc.Message() == nil {
panic(errors.New("%v: invalid AppendMutable on list with non-message type", x.desc.FullName()))
}
@@ -430,12 +434,12 @@ func (x *dynamicList) AppendMutable() pref.Value {
func (x *dynamicList) Truncate(n int) {
// Zero truncated elements to avoid keeping data live.
for i := n; i < len(x.list); i++ {
- x.list[i] = pref.Value{}
+ x.list[i] = protoreflect.Value{}
}
x.list = x.list[:n]
}
-func (x *dynamicList) NewElement() pref.Value {
+func (x *dynamicList) NewElement() protoreflect.Value {
return newListEntry(x.desc)
}
@@ -444,19 +448,19 @@ func (x *dynamicList) IsValid() bool {
}
type dynamicMap struct {
- desc pref.FieldDescriptor
- mapv map[interface{}]pref.Value
+ desc protoreflect.FieldDescriptor
+ mapv map[interface{}]protoreflect.Value
}
-func (x *dynamicMap) Get(k pref.MapKey) pref.Value { return x.mapv[k.Interface()] }
-func (x *dynamicMap) Set(k pref.MapKey, v pref.Value) {
+func (x *dynamicMap) Get(k protoreflect.MapKey) protoreflect.Value { return x.mapv[k.Interface()] }
+func (x *dynamicMap) Set(k protoreflect.MapKey, v protoreflect.Value) {
typecheckSingular(x.desc.MapKey(), k.Value())
typecheckSingular(x.desc.MapValue(), v)
x.mapv[k.Interface()] = v
}
-func (x *dynamicMap) Has(k pref.MapKey) bool { return x.Get(k).IsValid() }
-func (x *dynamicMap) Clear(k pref.MapKey) { delete(x.mapv, k.Interface()) }
-func (x *dynamicMap) Mutable(k pref.MapKey) pref.Value {
+func (x *dynamicMap) Has(k protoreflect.MapKey) bool { return x.Get(k).IsValid() }
+func (x *dynamicMap) Clear(k protoreflect.MapKey) { delete(x.mapv, k.Interface()) }
+func (x *dynamicMap) Mutable(k protoreflect.MapKey) protoreflect.Value {
if x.desc.MapValue().Message() == nil {
panic(errors.New("%v: invalid Mutable on map with non-message value type", x.desc.FullName()))
}
@@ -468,9 +472,9 @@ func (x *dynamicMap) Mutable(k pref.MapKey) pref.Value {
return v
}
func (x *dynamicMap) Len() int { return len(x.mapv) }
-func (x *dynamicMap) NewValue() pref.Value {
+func (x *dynamicMap) NewValue() protoreflect.Value {
if md := x.desc.MapValue().Message(); md != nil {
- return pref.ValueOfMessage(NewMessage(md).ProtoReflect())
+ return protoreflect.ValueOfMessage(NewMessage(md).ProtoReflect())
}
return x.desc.MapValue().Default()
}
@@ -478,15 +482,15 @@ func (x *dynamicMap) IsValid() bool {
return x.mapv != nil
}
-func (x *dynamicMap) Range(f func(pref.MapKey, pref.Value) bool) {
+func (x *dynamicMap) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) {
for k, v := range x.mapv {
- if !f(pref.ValueOf(k).MapKey(), v) {
+ if !f(protoreflect.ValueOf(k).MapKey(), v) {
return
}
}
}
-func isSet(fd pref.FieldDescriptor, v pref.Value) bool {
+func isSet(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
switch {
case fd.IsMap():
return v.Map().Len() > 0
@@ -494,34 +498,34 @@ func isSet(fd pref.FieldDescriptor, v pref.Value) bool {
return v.List().Len() > 0
case fd.ContainingOneof() != nil:
return true
- case fd.Syntax() == pref.Proto3 && !fd.IsExtension():
+ case fd.Syntax() == protoreflect.Proto3 && !fd.IsExtension():
switch fd.Kind() {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
return v.Bool()
- case pref.EnumKind:
+ case protoreflect.EnumKind:
return v.Enum() != 0
- case pref.Int32Kind, pref.Sint32Kind, pref.Int64Kind, pref.Sint64Kind, pref.Sfixed32Kind, pref.Sfixed64Kind:
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed32Kind, protoreflect.Sfixed64Kind:
return v.Int() != 0
- case pref.Uint32Kind, pref.Uint64Kind, pref.Fixed32Kind, pref.Fixed64Kind:
+ case protoreflect.Uint32Kind, protoreflect.Uint64Kind, protoreflect.Fixed32Kind, protoreflect.Fixed64Kind:
return v.Uint() != 0
- case pref.FloatKind, pref.DoubleKind:
+ case protoreflect.FloatKind, protoreflect.DoubleKind:
return v.Float() != 0 || math.Signbit(v.Float())
- case pref.StringKind:
+ case protoreflect.StringKind:
return v.String() != ""
- case pref.BytesKind:
+ case protoreflect.BytesKind:
return len(v.Bytes()) > 0
}
}
return true
}
-func typecheck(fd pref.FieldDescriptor, v pref.Value) {
+func typecheck(fd protoreflect.FieldDescriptor, v protoreflect.Value) {
if err := typeIsValid(fd, v); err != nil {
panic(err)
}
}
-func typeIsValid(fd pref.FieldDescriptor, v pref.Value) error {
+func typeIsValid(fd protoreflect.FieldDescriptor, v protoreflect.Value) error {
switch {
case !v.IsValid():
return errors.New("%v: assigning invalid value", fd.FullName())
@@ -547,40 +551,40 @@ func typeIsValid(fd pref.FieldDescriptor, v pref.Value) error {
}
}
-func typecheckSingular(fd pref.FieldDescriptor, v pref.Value) {
+func typecheckSingular(fd protoreflect.FieldDescriptor, v protoreflect.Value) {
if err := singularTypeIsValid(fd, v); err != nil {
panic(err)
}
}
-func singularTypeIsValid(fd pref.FieldDescriptor, v pref.Value) error {
+func singularTypeIsValid(fd protoreflect.FieldDescriptor, v protoreflect.Value) error {
vi := v.Interface()
var ok bool
switch fd.Kind() {
- case pref.BoolKind:
+ case protoreflect.BoolKind:
_, ok = vi.(bool)
- case pref.EnumKind:
+ case protoreflect.EnumKind:
// We could check against the valid set of enum values, but do not.
- _, ok = vi.(pref.EnumNumber)
- case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
+ _, ok = vi.(protoreflect.EnumNumber)
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
_, ok = vi.(int32)
- case pref.Uint32Kind, pref.Fixed32Kind:
+ case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
_, ok = vi.(uint32)
- case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
+ case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
_, ok = vi.(int64)
- case pref.Uint64Kind, pref.Fixed64Kind:
+ case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
_, ok = vi.(uint64)
- case pref.FloatKind:
+ case protoreflect.FloatKind:
_, ok = vi.(float32)
- case pref.DoubleKind:
+ case protoreflect.DoubleKind:
_, ok = vi.(float64)
- case pref.StringKind:
+ case protoreflect.StringKind:
_, ok = vi.(string)
- case pref.BytesKind:
+ case protoreflect.BytesKind:
_, ok = vi.([]byte)
- case pref.MessageKind, pref.GroupKind:
- var m pref.Message
- m, ok = vi.(pref.Message)
+ case protoreflect.MessageKind, protoreflect.GroupKind:
+ var m protoreflect.Message
+ m, ok = vi.(protoreflect.Message)
if ok && m.Descriptor().FullName() != fd.Message().FullName() {
return errors.New("%v: assigning invalid message type %v", fd.FullName(), m.Descriptor().FullName())
}
@@ -594,30 +598,30 @@ func singularTypeIsValid(fd pref.FieldDescriptor, v pref.Value) error {
return nil
}
-func newListEntry(fd pref.FieldDescriptor) pref.Value {
+func newListEntry(fd protoreflect.FieldDescriptor) protoreflect.Value {
switch fd.Kind() {
- case pref.BoolKind:
- return pref.ValueOfBool(false)
- case pref.EnumKind:
- return pref.ValueOfEnum(fd.Enum().Values().Get(0).Number())
- case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
- return pref.ValueOfInt32(0)
- case pref.Uint32Kind, pref.Fixed32Kind:
- return pref.ValueOfUint32(0)
- case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
- return pref.ValueOfInt64(0)
- case pref.Uint64Kind, pref.Fixed64Kind:
- return pref.ValueOfUint64(0)
- case pref.FloatKind:
- return pref.ValueOfFloat32(0)
- case pref.DoubleKind:
- return pref.ValueOfFloat64(0)
- case pref.StringKind:
- return pref.ValueOfString("")
- case pref.BytesKind:
- return pref.ValueOfBytes(nil)
- case pref.MessageKind, pref.GroupKind:
- return pref.ValueOfMessage(NewMessage(fd.Message()).ProtoReflect())
+ case protoreflect.BoolKind:
+ return protoreflect.ValueOfBool(false)
+ case protoreflect.EnumKind:
+ return protoreflect.ValueOfEnum(fd.Enum().Values().Get(0).Number())
+ case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
+ return protoreflect.ValueOfInt32(0)
+ case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
+ return protoreflect.ValueOfUint32(0)
+ case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
+ return protoreflect.ValueOfInt64(0)
+ case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
+ return protoreflect.ValueOfUint64(0)
+ case protoreflect.FloatKind:
+ return protoreflect.ValueOfFloat32(0)
+ case protoreflect.DoubleKind:
+ return protoreflect.ValueOfFloat64(0)
+ case protoreflect.StringKind:
+ return protoreflect.ValueOfString("")
+ case protoreflect.BytesKind:
+ return protoreflect.ValueOfBytes(nil)
+ case protoreflect.MessageKind, protoreflect.GroupKind:
+ return protoreflect.ValueOfMessage(NewMessage(fd.Message()).ProtoReflect())
}
panic(errors.New("%v: unknown kind %v", fd.FullName(), fd.Kind()))
}
@@ -641,73 +645,73 @@ func newListEntry(fd pref.FieldDescriptor) pref.Value {
// is determined by these methods, and is therefore equivalent to the Go type
// used to represent a protoreflect.Value. See the protoreflect.Value
// documentation for more details.
-func NewExtensionType(desc pref.ExtensionDescriptor) pref.ExtensionType {
- if xt, ok := desc.(pref.ExtensionTypeDescriptor); ok {
+func NewExtensionType(desc protoreflect.ExtensionDescriptor) protoreflect.ExtensionType {
+ if xt, ok := desc.(protoreflect.ExtensionTypeDescriptor); ok {
desc = xt.Descriptor()
}
return extensionType{extensionTypeDescriptor{desc}}
}
-func (xt extensionType) New() pref.Value {
+func (xt extensionType) New() protoreflect.Value {
switch {
case xt.desc.IsMap():
- return pref.ValueOfMap(&dynamicMap{
+ return protoreflect.ValueOfMap(&dynamicMap{
desc: xt.desc,
- mapv: make(map[interface{}]pref.Value),
+ mapv: make(map[interface{}]protoreflect.Value),
})
case xt.desc.IsList():
- return pref.ValueOfList(&dynamicList{desc: xt.desc})
+ return protoreflect.ValueOfList(&dynamicList{desc: xt.desc})
case xt.desc.Message() != nil:
- return pref.ValueOfMessage(NewMessage(xt.desc.Message()))
+ return protoreflect.ValueOfMessage(NewMessage(xt.desc.Message()))
default:
return xt.desc.Default()
}
}
-func (xt extensionType) Zero() pref.Value {
+func (xt extensionType) Zero() protoreflect.Value {
switch {
case xt.desc.IsMap():
- return pref.ValueOfMap(&dynamicMap{desc: xt.desc})
- case xt.desc.Cardinality() == pref.Repeated:
- return pref.ValueOfList(emptyList{desc: xt.desc})
+ return protoreflect.ValueOfMap(&dynamicMap{desc: xt.desc})
+ case xt.desc.Cardinality() == protoreflect.Repeated:
+ return protoreflect.ValueOfList(emptyList{desc: xt.desc})
case xt.desc.Message() != nil:
- return pref.ValueOfMessage(&Message{typ: messageType{xt.desc.Message()}})
+ return protoreflect.ValueOfMessage(&Message{typ: messageType{xt.desc.Message()}})
default:
return xt.desc.Default()
}
}
-func (xt extensionType) TypeDescriptor() pref.ExtensionTypeDescriptor {
+func (xt extensionType) TypeDescriptor() protoreflect.ExtensionTypeDescriptor {
return xt.desc
}
-func (xt extensionType) ValueOf(iv interface{}) pref.Value {
- v := pref.ValueOf(iv)
+func (xt extensionType) ValueOf(iv interface{}) protoreflect.Value {
+ v := protoreflect.ValueOf(iv)
typecheck(xt.desc, v)
return v
}
-func (xt extensionType) InterfaceOf(v pref.Value) interface{} {
+func (xt extensionType) InterfaceOf(v protoreflect.Value) interface{} {
typecheck(xt.desc, v)
return v.Interface()
}
func (xt extensionType) IsValidInterface(iv interface{}) bool {
- return typeIsValid(xt.desc, pref.ValueOf(iv)) == nil
+ return typeIsValid(xt.desc, protoreflect.ValueOf(iv)) == nil
}
-func (xt extensionType) IsValidValue(v pref.Value) bool {
+func (xt extensionType) IsValidValue(v protoreflect.Value) bool {
return typeIsValid(xt.desc, v) == nil
}
type extensionTypeDescriptor struct {
- pref.ExtensionDescriptor
+ protoreflect.ExtensionDescriptor
}
-func (xt extensionTypeDescriptor) Type() pref.ExtensionType {
+func (xt extensionTypeDescriptor) Type() protoreflect.ExtensionType {
return extensionType{xt}
}
-func (xt extensionTypeDescriptor) Descriptor() pref.ExtensionDescriptor {
+func (xt extensionTypeDescriptor) Descriptor() protoreflect.ExtensionDescriptor {
return xt.ExtensionDescriptor
}
diff --git a/types/dynamicpb/dynamic_test.go b/types/dynamicpb/dynamic_test.go
index 6835d3e1..99d77d0a 100644
--- a/types/dynamicpb/dynamic_test.go
+++ b/types/dynamicpb/dynamic_test.go
@@ -8,8 +8,8 @@ import (
"testing"
"google.golang.org/protobuf/proto"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/testing/prototest"
"google.golang.org/protobuf/types/dynamicpb"
@@ -40,7 +40,7 @@ func TestDynamicExtensions(t *testing.T) {
}
func TestDynamicEnums(t *testing.T) {
- for _, enum := range []pref.Enum{
+ for _, enum := range []protoreflect.Enum{
testpb.TestAllTypes_FOO,
test3pb.TestAllTypes_FOO,
} {
@@ -51,24 +51,24 @@ func TestDynamicEnums(t *testing.T) {
type extResolver struct{}
-func (extResolver) FindExtensionByName(field pref.FullName) (pref.ExtensionType, error) {
- xt, err := preg.GlobalTypes.FindExtensionByName(field)
+func (extResolver) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error) {
+ xt, err := protoregistry.GlobalTypes.FindExtensionByName(field)
if err != nil {
return nil, err
}
return dynamicpb.NewExtensionType(xt.TypeDescriptor().Descriptor()), nil
}
-func (extResolver) FindExtensionByNumber(message pref.FullName, field pref.FieldNumber) (pref.ExtensionType, error) {
- xt, err := preg.GlobalTypes.FindExtensionByNumber(message, field)
+func (extResolver) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error) {
+ xt, err := protoregistry.GlobalTypes.FindExtensionByNumber(message, field)
if err != nil {
return nil, err
}
return dynamicpb.NewExtensionType(xt.TypeDescriptor().Descriptor()), nil
}
-func (extResolver) RangeExtensionsByMessage(message pref.FullName, f func(pref.ExtensionType) bool) {
- preg.GlobalTypes.RangeExtensionsByMessage(message, func(xt pref.ExtensionType) bool {
+func (extResolver) RangeExtensionsByMessage(message protoreflect.FullName, f func(protoreflect.ExtensionType) bool) {
+ protoregistry.GlobalTypes.RangeExtensionsByMessage(message, func(xt protoreflect.ExtensionType) bool {
return f(dynamicpb.NewExtensionType(xt.TypeDescriptor().Descriptor()))
})
}