aboutsummaryrefslogtreecommitdiff
path: root/internal/impl
diff options
context:
space:
mode:
Diffstat (limited to 'internal/impl')
-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.go229
-rw-r--r--internal/impl/convert_list.go42
-rw-r--r--internal/impl/convert_map.go32
-rw-r--r--internal/impl/decode.go21
-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_enum.go57
-rw-r--r--internal/impl/legacy_export.go18
-rw-r--r--internal/impl/legacy_extension.go100
-rw-r--r--internal/impl/legacy_file_test.go40
-rw-r--r--internal/impl/legacy_message.go122
-rw-r--r--internal/impl/legacy_test.go52
-rw-r--r--internal/impl/merge.go32
-rw-r--r--internal/impl/message.go41
-rw-r--r--internal/impl/message_reflect.go74
-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
28 files changed, 896 insertions, 898 deletions
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..185ef2ef 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)
@@ -59,7 +59,6 @@ func NewConverter(t reflect.Type, fd pref.FieldDescriptor) Converter {
default:
return newSingularConverter(t, fd)
}
- panic(fmt.Sprintf("invalid Go type %v for field %v", t, fd.FullName()))
}
var (
@@ -76,68 +75,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 +144,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 +330,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 +402,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 +418,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 +429,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 +459,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 +477,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/decode.go b/internal/impl/decode.go
index c65b0325..cda0520c 100644
--- a/internal/impl/decode.go
+++ b/internal/impl/decode.go
@@ -12,9 +12,8 @@ import (
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/runtime/protoiface"
- piface "google.golang.org/protobuf/runtime/protoiface"
)
var errDecode = errors.New("cannot parse invalid wire-format data")
@@ -38,14 +37,16 @@ func (o unmarshalOptions) Options() proto.UnmarshalOptions {
}
}
-func (o unmarshalOptions) DiscardUnknown() bool { return o.flags&piface.UnmarshalDiscardUnknown != 0 }
+func (o unmarshalOptions) DiscardUnknown() bool {
+ return o.flags&protoiface.UnmarshalDiscardUnknown != 0
+}
func (o unmarshalOptions) IsDefault() bool {
- return o.flags == 0 && o.resolver == preg.GlobalTypes
+ return o.flags == 0 && o.resolver == protoregistry.GlobalTypes
}
var lazyUnmarshalOptions = unmarshalOptions{
- resolver: preg.GlobalTypes,
+ resolver: protoregistry.GlobalTypes,
depth: protowire.DefaultRecursionLimit,
}
@@ -55,7 +56,7 @@ type unmarshalOutput struct {
}
// unmarshal is protoreflect.Methods.Unmarshal.
-func (mi *MessageInfo) unmarshal(in piface.UnmarshalInput) (piface.UnmarshalOutput, error) {
+func (mi *MessageInfo) unmarshal(in protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) {
var p pointer
if ms, ok := in.Message.(*messageState); ok {
p = ms.pointer()
@@ -67,11 +68,11 @@ func (mi *MessageInfo) unmarshal(in piface.UnmarshalInput) (piface.UnmarshalOutp
resolver: in.Resolver,
depth: in.Depth,
})
- var flags piface.UnmarshalOutputFlags
+ var flags protoiface.UnmarshalOutputFlags
if out.initialized {
- flags |= piface.UnmarshalInitialized
+ flags |= protoiface.UnmarshalInitialized
}
- return piface.UnmarshalOutput{
+ return protoiface.UnmarshalOutput{
Flags: flags,
}, err
}
@@ -210,7 +211,7 @@ func (mi *MessageInfo) unmarshalExtension(b []byte, num protowire.Number, wtyp p
var err error
xt, err = opts.resolver.FindExtensionByNumber(mi.Desc.FullName(), num)
if err != nil {
- if err == preg.NotFound {
+ if err == protoregistry.NotFound {
return out, errUnknown
}
return out, errors.New("%v: unable to resolve extension %v: %v", mi.Desc.FullName(), num, err)
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_enum.go b/internal/impl/legacy_enum.go
index f7d7ffb5..c2a803bb 100644
--- a/internal/impl/legacy_enum.go
+++ b/internal/impl/legacy_enum.go
@@ -13,13 +13,12 @@ import (
"google.golang.org/protobuf/internal/filedesc"
"google.golang.org/protobuf/internal/strs"
"google.golang.org/protobuf/reflect/protoreflect"
- pref "google.golang.org/protobuf/reflect/protoreflect"
)
// legacyEnumName returns the name of enums used in legacy code.
// It is neither the protobuf full name nor the qualified Go name,
// but rather an odd hybrid of both.
-func legacyEnumName(ed pref.EnumDescriptor) string {
+func legacyEnumName(ed protoreflect.EnumDescriptor) string {
var protoPkg string
enumName := string(ed.FullName())
if fd := ed.ParentFile(); fd != nil {
@@ -34,68 +33,68 @@ func legacyEnumName(ed pref.EnumDescriptor) string {
// legacyWrapEnum wraps v as a protoreflect.Enum,
// where v must be a int32 kind and not implement the v2 API already.
-func legacyWrapEnum(v reflect.Value) pref.Enum {
+func legacyWrapEnum(v reflect.Value) protoreflect.Enum {
et := legacyLoadEnumType(v.Type())
- return et.New(pref.EnumNumber(v.Int()))
+ return et.New(protoreflect.EnumNumber(v.Int()))
}
var legacyEnumTypeCache sync.Map // map[reflect.Type]protoreflect.EnumType
// legacyLoadEnumType dynamically loads a protoreflect.EnumType for t,
// where t must be an int32 kind and not implement the v2 API already.
-func legacyLoadEnumType(t reflect.Type) pref.EnumType {
+func legacyLoadEnumType(t reflect.Type) protoreflect.EnumType {
// Fast-path: check if a EnumType is cached for this concrete type.
if et, ok := legacyEnumTypeCache.Load(t); ok {
- return et.(pref.EnumType)
+ return et.(protoreflect.EnumType)
}
// Slow-path: derive enum descriptor and initialize EnumType.
- var et pref.EnumType
+ var et protoreflect.EnumType
ed := LegacyLoadEnumDesc(t)
et = &legacyEnumType{
desc: ed,
goType: t,
}
if et, ok := legacyEnumTypeCache.LoadOrStore(t, et); ok {
- return et.(pref.EnumType)
+ return et.(protoreflect.EnumType)
}
return et
}
type legacyEnumType struct {
- desc pref.EnumDescriptor
+ desc protoreflect.EnumDescriptor
goType reflect.Type
m sync.Map // map[protoreflect.EnumNumber]proto.Enum
}
-func (t *legacyEnumType) New(n pref.EnumNumber) pref.Enum {
+func (t *legacyEnumType) New(n protoreflect.EnumNumber) protoreflect.Enum {
if e, ok := t.m.Load(n); ok {
- return e.(pref.Enum)
+ return e.(protoreflect.Enum)
}
e := &legacyEnumWrapper{num: n, pbTyp: t, goTyp: t.goType}
t.m.Store(n, e)
return e
}
-func (t *legacyEnumType) Descriptor() pref.EnumDescriptor {
+func (t *legacyEnumType) Descriptor() protoreflect.EnumDescriptor {
return t.desc
}
type legacyEnumWrapper struct {
- num pref.EnumNumber
- pbTyp pref.EnumType
+ num protoreflect.EnumNumber
+ pbTyp protoreflect.EnumType
goTyp reflect.Type
}
-func (e *legacyEnumWrapper) Descriptor() pref.EnumDescriptor {
+func (e *legacyEnumWrapper) Descriptor() protoreflect.EnumDescriptor {
return e.pbTyp.Descriptor()
}
-func (e *legacyEnumWrapper) Type() pref.EnumType {
+func (e *legacyEnumWrapper) Type() protoreflect.EnumType {
return e.pbTyp
}
-func (e *legacyEnumWrapper) Number() pref.EnumNumber {
+func (e *legacyEnumWrapper) Number() protoreflect.EnumNumber {
return e.num
}
-func (e *legacyEnumWrapper) ProtoReflect() pref.Enum {
+func (e *legacyEnumWrapper) ProtoReflect() protoreflect.Enum {
return e
}
func (e *legacyEnumWrapper) protoUnwrap() interface{} {
@@ -105,8 +104,8 @@ func (e *legacyEnumWrapper) protoUnwrap() interface{} {
}
var (
- _ pref.Enum = (*legacyEnumWrapper)(nil)
- _ unwrapper = (*legacyEnumWrapper)(nil)
+ _ protoreflect.Enum = (*legacyEnumWrapper)(nil)
+ _ unwrapper = (*legacyEnumWrapper)(nil)
)
var legacyEnumDescCache sync.Map // map[reflect.Type]protoreflect.EnumDescriptor
@@ -115,15 +114,15 @@ var legacyEnumDescCache sync.Map // map[reflect.Type]protoreflect.EnumDescriptor
// which must be an int32 kind and not implement the v2 API already.
//
// This is exported for testing purposes.
-func LegacyLoadEnumDesc(t reflect.Type) pref.EnumDescriptor {
+func LegacyLoadEnumDesc(t reflect.Type) protoreflect.EnumDescriptor {
// Fast-path: check if an EnumDescriptor is cached for this concrete type.
if ed, ok := legacyEnumDescCache.Load(t); ok {
- return ed.(pref.EnumDescriptor)
+ return ed.(protoreflect.EnumDescriptor)
}
// Slow-path: initialize EnumDescriptor from the raw descriptor.
ev := reflect.Zero(t).Interface()
- if _, ok := ev.(pref.Enum); ok {
+ if _, ok := ev.(protoreflect.Enum); ok {
panic(fmt.Sprintf("%v already implements proto.Enum", t))
}
edV1, ok := ev.(enumV1)
@@ -132,7 +131,7 @@ func LegacyLoadEnumDesc(t reflect.Type) pref.EnumDescriptor {
}
b, idxs := edV1.EnumDescriptor()
- var ed pref.EnumDescriptor
+ var ed protoreflect.EnumDescriptor
if len(idxs) == 1 {
ed = legacyLoadFileDesc(b).Enums().Get(idxs[0])
} else {
@@ -158,10 +157,10 @@ var aberrantEnumDescCache sync.Map // map[reflect.Type]protoreflect.EnumDescript
// We are unable to use the global enum registry since it is
// unfortunately keyed by the protobuf full name, which we also do not know.
// Thus, this produces some bogus enum descriptor based on the Go type name.
-func aberrantLoadEnumDesc(t reflect.Type) pref.EnumDescriptor {
+func aberrantLoadEnumDesc(t reflect.Type) protoreflect.EnumDescriptor {
// Fast-path: check if an EnumDescriptor is cached for this concrete type.
if ed, ok := aberrantEnumDescCache.Load(t); ok {
- return ed.(pref.EnumDescriptor)
+ return ed.(protoreflect.EnumDescriptor)
}
// Slow-path: construct a bogus, but unique EnumDescriptor.
@@ -182,7 +181,7 @@ func aberrantLoadEnumDesc(t reflect.Type) pref.EnumDescriptor {
// An exhaustive query is clearly impractical, but can be best-effort.
if ed, ok := aberrantEnumDescCache.LoadOrStore(t, ed); ok {
- return ed.(pref.EnumDescriptor)
+ return ed.(protoreflect.EnumDescriptor)
}
return ed
}
@@ -192,7 +191,7 @@ func aberrantLoadEnumDesc(t reflect.Type) pref.EnumDescriptor {
// It should be sufficiently unique within a program.
//
// This is exported for testing purposes.
-func AberrantDeriveFullName(t reflect.Type) pref.FullName {
+func AberrantDeriveFullName(t reflect.Type) protoreflect.FullName {
sanitize := func(r rune) rune {
switch {
case r == '/':
@@ -215,5 +214,5 @@ func AberrantDeriveFullName(t reflect.Type) pref.FullName {
ss[i] = "x" + s
}
}
- return pref.FullName(strings.Join(ss, "."))
+ return protoreflect.FullName(strings.Join(ss, "."))
}
diff --git a/internal/impl/legacy_export.go b/internal/impl/legacy_export.go
index e3fb0b57..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)
}
@@ -81,8 +81,8 @@ func (Export) CompressGZIP(in []byte) (out []byte) {
blockHeader[0] = 0x01 // final bit per RFC 1951, section 3.2.3.
blockSize = len(in)
}
- binary.LittleEndian.PutUint16(blockHeader[1:3], uint16(blockSize)^0x0000)
- binary.LittleEndian.PutUint16(blockHeader[3:5], uint16(blockSize)^0xffff)
+ binary.LittleEndian.PutUint16(blockHeader[1:3], uint16(blockSize))
+ binary.LittleEndian.PutUint16(blockHeader[3:5], ^uint16(blockSize))
out = append(out, blockHeader[:]...)
out = append(out, in[:blockSize]...)
in = in[blockSize:]
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_message.go b/internal/impl/legacy_message.go
index 029feeef..61c483fa 100644
--- a/internal/impl/legacy_message.go
+++ b/internal/impl/legacy_message.go
@@ -16,14 +16,12 @@ import (
"google.golang.org/protobuf/internal/filedesc"
"google.golang.org/protobuf/internal/strs"
"google.golang.org/protobuf/reflect/protoreflect"
- pref "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/runtime/protoiface"
- piface "google.golang.org/protobuf/runtime/protoiface"
)
// legacyWrapMessage wraps v as a protoreflect.Message,
// where v must be a *struct kind and not implement the v2 API already.
-func legacyWrapMessage(v reflect.Value) pref.Message {
+func legacyWrapMessage(v reflect.Value) protoreflect.Message {
t := v.Type()
if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {
return aberrantMessage{v: v}
@@ -35,7 +33,7 @@ func legacyWrapMessage(v reflect.Value) pref.Message {
// legacyLoadMessageType dynamically loads a protoreflect.Type for t,
// where t must be not implement the v2 API already.
// The provided name is used if it cannot be determined from the message.
-func legacyLoadMessageType(t reflect.Type, name pref.FullName) protoreflect.MessageType {
+func legacyLoadMessageType(t reflect.Type, name protoreflect.FullName) protoreflect.MessageType {
if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {
return aberrantMessageType{t}
}
@@ -47,7 +45,7 @@ var legacyMessageTypeCache sync.Map // map[reflect.Type]*MessageInfo
// legacyLoadMessageInfo dynamically loads a *MessageInfo for t,
// where t must be a *struct kind and not implement the v2 API already.
// The provided name is used if it cannot be determined from the message.
-func legacyLoadMessageInfo(t reflect.Type, name pref.FullName) *MessageInfo {
+func legacyLoadMessageInfo(t reflect.Type, name protoreflect.FullName) *MessageInfo {
// Fast-path: check if a MessageInfo is cached for this concrete type.
if mt, ok := legacyMessageTypeCache.Load(t); ok {
return mt.(*MessageInfo)
@@ -68,7 +66,7 @@ func legacyLoadMessageInfo(t reflect.Type, name pref.FullName) *MessageInfo {
// supports deterministic serialization or not, but this
// preserves the v1 implementation's behavior of always
// calling Marshal methods when present.
- mi.methods.Flags |= piface.SupportMarshalDeterministic
+ mi.methods.Flags |= protoiface.SupportMarshalDeterministic
}
if _, hasUnmarshal = v.(legacyUnmarshaler); hasUnmarshal {
mi.methods.Unmarshal = legacyUnmarshal
@@ -89,18 +87,18 @@ var legacyMessageDescCache sync.Map // map[reflect.Type]protoreflect.MessageDesc
// which should be a *struct kind and must not implement the v2 API already.
//
// This is exported for testing purposes.
-func LegacyLoadMessageDesc(t reflect.Type) pref.MessageDescriptor {
+func LegacyLoadMessageDesc(t reflect.Type) protoreflect.MessageDescriptor {
return legacyLoadMessageDesc(t, "")
}
-func legacyLoadMessageDesc(t reflect.Type, name pref.FullName) pref.MessageDescriptor {
+func legacyLoadMessageDesc(t reflect.Type, name protoreflect.FullName) protoreflect.MessageDescriptor {
// Fast-path: check if a MessageDescriptor is cached for this concrete type.
if mi, ok := legacyMessageDescCache.Load(t); ok {
- return mi.(pref.MessageDescriptor)
+ return mi.(protoreflect.MessageDescriptor)
}
// Slow-path: initialize MessageDescriptor from the raw descriptor.
mv := reflect.Zero(t).Interface()
- if _, ok := mv.(pref.ProtoMessage); ok {
+ if _, ok := mv.(protoreflect.ProtoMessage); ok {
panic(fmt.Sprintf("%v already implements proto.Message", t))
}
mdV1, ok := mv.(messageV1)
@@ -164,7 +162,7 @@ var (
//
// This is a best-effort derivation of the message descriptor using the protobuf
// tags on the struct fields.
-func aberrantLoadMessageDesc(t reflect.Type, name pref.FullName) pref.MessageDescriptor {
+func aberrantLoadMessageDesc(t reflect.Type, name protoreflect.FullName) protoreflect.MessageDescriptor {
aberrantMessageDescLock.Lock()
defer aberrantMessageDescLock.Unlock()
if aberrantMessageDescCache == nil {
@@ -172,7 +170,7 @@ func aberrantLoadMessageDesc(t reflect.Type, name pref.FullName) pref.MessageDes
}
return aberrantLoadMessageDescReentrant(t, name)
}
-func aberrantLoadMessageDescReentrant(t reflect.Type, name pref.FullName) pref.MessageDescriptor {
+func aberrantLoadMessageDescReentrant(t reflect.Type, name protoreflect.FullName) protoreflect.MessageDescriptor {
// Fast-path: check if an MessageDescriptor is cached for this concrete type.
if md, ok := aberrantMessageDescCache[t]; ok {
return md
@@ -225,9 +223,9 @@ func aberrantLoadMessageDescReentrant(t reflect.Type, name pref.FullName) pref.M
vs := fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[0]
for i := 0; i < vs.Len(); i++ {
v := vs.Index(i)
- md.L2.ExtensionRanges.List = append(md.L2.ExtensionRanges.List, [2]pref.FieldNumber{
- pref.FieldNumber(v.FieldByName("Start").Int()),
- pref.FieldNumber(v.FieldByName("End").Int() + 1),
+ md.L2.ExtensionRanges.List = append(md.L2.ExtensionRanges.List, [2]protoreflect.FieldNumber{
+ protoreflect.FieldNumber(v.FieldByName("Start").Int()),
+ protoreflect.FieldNumber(v.FieldByName("End").Int() + 1),
})
md.L2.ExtensionRangeOptions = append(md.L2.ExtensionRangeOptions, nil)
}
@@ -245,7 +243,7 @@ func aberrantLoadMessageDescReentrant(t reflect.Type, name pref.FullName) pref.M
n := len(md.L2.Oneofs.List)
md.L2.Oneofs.List = append(md.L2.Oneofs.List, filedesc.Oneof{})
od := &md.L2.Oneofs.List[n]
- od.L0.FullName = md.FullName().Append(pref.Name(tag))
+ od.L0.FullName = md.FullName().Append(protoreflect.Name(tag))
od.L0.ParentFile = md.L0.ParentFile
od.L0.Parent = md
od.L0.Index = n
@@ -267,14 +265,14 @@ func aberrantLoadMessageDescReentrant(t reflect.Type, name pref.FullName) pref.M
return md
}
-func aberrantDeriveMessageName(t reflect.Type, name pref.FullName) pref.FullName {
+func aberrantDeriveMessageName(t reflect.Type, name protoreflect.FullName) protoreflect.FullName {
if name.IsValid() {
return name
}
func() {
defer func() { recover() }() // swallow possible nil panics
if m, ok := reflect.Zero(t).Interface().(interface{ XXX_MessageName() string }); ok {
- name = pref.FullName(m.XXX_MessageName())
+ name = protoreflect.FullName(m.XXX_MessageName())
}
}()
if name.IsValid() {
@@ -305,7 +303,7 @@ func aberrantAppendField(md *filedesc.Message, goType reflect.Type, tag, tagKey,
fd.L0.Index = n
if fd.L1.IsWeak || fd.L1.HasPacked {
- fd.L1.Options = func() pref.ProtoMessage {
+ fd.L1.Options = func() protoreflect.ProtoMessage {
opts := descopts.Field.ProtoReflect().New()
if fd.L1.IsWeak {
opts.Set(opts.Descriptor().Fields().ByName("weak"), protoreflect.ValueOfBool(true))
@@ -318,17 +316,17 @@ func aberrantAppendField(md *filedesc.Message, goType reflect.Type, tag, tagKey,
}
// Populate Enum and Message.
- if fd.Enum() == nil && fd.Kind() == pref.EnumKind {
+ if fd.Enum() == nil && fd.Kind() == protoreflect.EnumKind {
switch v := reflect.Zero(t).Interface().(type) {
- case pref.Enum:
+ case protoreflect.Enum:
fd.L1.Enum = v.Descriptor()
default:
fd.L1.Enum = LegacyLoadEnumDesc(t)
}
}
- if fd.Message() == nil && (fd.Kind() == pref.MessageKind || fd.Kind() == pref.GroupKind) {
+ if fd.Message() == nil && (fd.Kind() == protoreflect.MessageKind || fd.Kind() == protoreflect.GroupKind) {
switch v := reflect.Zero(t).Interface().(type) {
- case pref.ProtoMessage:
+ case protoreflect.ProtoMessage:
fd.L1.Message = v.ProtoReflect().Descriptor()
case messageV1:
fd.L1.Message = LegacyLoadMessageDesc(t)
@@ -337,13 +335,13 @@ func aberrantAppendField(md *filedesc.Message, goType reflect.Type, tag, tagKey,
n := len(md.L1.Messages.List)
md.L1.Messages.List = append(md.L1.Messages.List, filedesc.Message{L2: new(filedesc.MessageL2)})
md2 := &md.L1.Messages.List[n]
- md2.L0.FullName = md.FullName().Append(pref.Name(strs.MapEntryName(string(fd.Name()))))
+ md2.L0.FullName = md.FullName().Append(protoreflect.Name(strs.MapEntryName(string(fd.Name()))))
md2.L0.ParentFile = md.L0.ParentFile
md2.L0.Parent = md
md2.L0.Index = n
md2.L1.IsMapEntry = true
- md2.L2.Options = func() pref.ProtoMessage {
+ md2.L2.Options = func() protoreflect.ProtoMessage {
opts := descopts.Message.ProtoReflect().New()
opts.Set(opts.Descriptor().Fields().ByName("map_entry"), protoreflect.ValueOfBool(true))
return opts.Interface()
@@ -364,8 +362,8 @@ type placeholderEnumValues struct {
protoreflect.EnumValueDescriptors
}
-func (placeholderEnumValues) ByNumber(n pref.EnumNumber) pref.EnumValueDescriptor {
- return filedesc.PlaceholderEnumValue(pref.FullName(fmt.Sprintf("UNKNOWN_%d", n)))
+func (placeholderEnumValues) ByNumber(n protoreflect.EnumNumber) protoreflect.EnumValueDescriptor {
+ return filedesc.PlaceholderEnumValue(protoreflect.FullName(fmt.Sprintf("UNKNOWN_%d", n)))
}
// legacyMarshaler is the proto.Marshaler interface superseded by protoiface.Methoder.
@@ -383,7 +381,7 @@ type legacyMerger interface {
Merge(protoiface.MessageV1)
}
-var aberrantProtoMethods = &piface.Methods{
+var aberrantProtoMethods = &protoiface.Methods{
Marshal: legacyMarshal,
Unmarshal: legacyUnmarshal,
Merge: legacyMerge,
@@ -392,40 +390,40 @@ var aberrantProtoMethods = &piface.Methods{
// supports deterministic serialization or not, but this
// preserves the v1 implementation's behavior of always
// calling Marshal methods when present.
- Flags: piface.SupportMarshalDeterministic,
+ Flags: protoiface.SupportMarshalDeterministic,
}
-func legacyMarshal(in piface.MarshalInput) (piface.MarshalOutput, error) {
+func legacyMarshal(in protoiface.MarshalInput) (protoiface.MarshalOutput, error) {
v := in.Message.(unwrapper).protoUnwrap()
marshaler, ok := v.(legacyMarshaler)
if !ok {
- return piface.MarshalOutput{}, errors.New("%T does not implement Marshal", v)
+ return protoiface.MarshalOutput{}, errors.New("%T does not implement Marshal", v)
}
out, err := marshaler.Marshal()
if in.Buf != nil {
out = append(in.Buf, out...)
}
- return piface.MarshalOutput{
+ return protoiface.MarshalOutput{
Buf: out,
}, err
}
-func legacyUnmarshal(in piface.UnmarshalInput) (piface.UnmarshalOutput, error) {
+func legacyUnmarshal(in protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) {
v := in.Message.(unwrapper).protoUnwrap()
unmarshaler, ok := v.(legacyUnmarshaler)
if !ok {
- return piface.UnmarshalOutput{}, errors.New("%T does not implement Unmarshal", v)
+ return protoiface.UnmarshalOutput{}, errors.New("%T does not implement Unmarshal", v)
}
- return piface.UnmarshalOutput{}, unmarshaler.Unmarshal(in.Buf)
+ return protoiface.UnmarshalOutput{}, unmarshaler.Unmarshal(in.Buf)
}
-func legacyMerge(in piface.MergeInput) piface.MergeOutput {
+func legacyMerge(in protoiface.MergeInput) protoiface.MergeOutput {
// Check whether this supports the legacy merger.
dstv := in.Destination.(unwrapper).protoUnwrap()
merger, ok := dstv.(legacyMerger)
if ok {
merger.Merge(Export{}.ProtoMessageV1Of(in.Source))
- return piface.MergeOutput{Flags: piface.MergeComplete}
+ return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
}
// If legacy merger is unavailable, implement merge in terms of
@@ -433,29 +431,29 @@ func legacyMerge(in piface.MergeInput) piface.MergeOutput {
srcv := in.Source.(unwrapper).protoUnwrap()
marshaler, ok := srcv.(legacyMarshaler)
if !ok {
- return piface.MergeOutput{}
+ return protoiface.MergeOutput{}
}
dstv = in.Destination.(unwrapper).protoUnwrap()
unmarshaler, ok := dstv.(legacyUnmarshaler)
if !ok {
- return piface.MergeOutput{}
+ return protoiface.MergeOutput{}
}
if !in.Source.IsValid() {
// Legacy Marshal methods may not function on nil messages.
// Check for a typed nil source only after we confirm that
// legacy Marshal/Unmarshal methods are present, for
// consistency.
- return piface.MergeOutput{Flags: piface.MergeComplete}
+ return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
}
b, err := marshaler.Marshal()
if err != nil {
- return piface.MergeOutput{}
+ return protoiface.MergeOutput{}
}
err = unmarshaler.Unmarshal(b)
if err != nil {
- return piface.MergeOutput{}
+ return protoiface.MergeOutput{}
}
- return piface.MergeOutput{Flags: piface.MergeComplete}
+ return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
}
// aberrantMessageType implements MessageType for all types other than pointer-to-struct.
@@ -463,19 +461,19 @@ type aberrantMessageType struct {
t reflect.Type
}
-func (mt aberrantMessageType) New() pref.Message {
+func (mt aberrantMessageType) New() protoreflect.Message {
if mt.t.Kind() == reflect.Ptr {
return aberrantMessage{reflect.New(mt.t.Elem())}
}
return aberrantMessage{reflect.Zero(mt.t)}
}
-func (mt aberrantMessageType) Zero() pref.Message {
+func (mt aberrantMessageType) Zero() protoreflect.Message {
return aberrantMessage{reflect.Zero(mt.t)}
}
func (mt aberrantMessageType) GoType() reflect.Type {
return mt.t
}
-func (mt aberrantMessageType) Descriptor() pref.MessageDescriptor {
+func (mt aberrantMessageType) Descriptor() protoreflect.MessageDescriptor {
return LegacyLoadMessageDesc(mt.t)
}
@@ -499,56 +497,56 @@ func (m aberrantMessage) Reset() {
}
}
-func (m aberrantMessage) ProtoReflect() pref.Message {
+func (m aberrantMessage) ProtoReflect() protoreflect.Message {
return m
}
-func (m aberrantMessage) Descriptor() pref.MessageDescriptor {
+func (m aberrantMessage) Descriptor() protoreflect.MessageDescriptor {
return LegacyLoadMessageDesc(m.v.Type())
}
-func (m aberrantMessage) Type() pref.MessageType {
+func (m aberrantMessage) Type() protoreflect.MessageType {
return aberrantMessageType{m.v.Type()}
}
-func (m aberrantMessage) New() pref.Message {
+func (m aberrantMessage) New() protoreflect.Message {
if m.v.Type().Kind() == reflect.Ptr {
return aberrantMessage{reflect.New(m.v.Type().Elem())}
}
return aberrantMessage{reflect.Zero(m.v.Type())}
}
-func (m aberrantMessage) Interface() pref.ProtoMessage {
+func (m aberrantMessage) Interface() protoreflect.ProtoMessage {
return m
}
-func (m aberrantMessage) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
+func (m aberrantMessage) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
return
}
-func (m aberrantMessage) Has(pref.FieldDescriptor) bool {
+func (m aberrantMessage) Has(protoreflect.FieldDescriptor) bool {
return false
}
-func (m aberrantMessage) Clear(pref.FieldDescriptor) {
+func (m aberrantMessage) Clear(protoreflect.FieldDescriptor) {
panic("invalid Message.Clear on " + string(m.Descriptor().FullName()))
}
-func (m aberrantMessage) Get(fd pref.FieldDescriptor) pref.Value {
+func (m aberrantMessage) Get(fd protoreflect.FieldDescriptor) protoreflect.Value {
if fd.Default().IsValid() {
return fd.Default()
}
panic("invalid Message.Get on " + string(m.Descriptor().FullName()))
}
-func (m aberrantMessage) Set(pref.FieldDescriptor, pref.Value) {
+func (m aberrantMessage) Set(protoreflect.FieldDescriptor, protoreflect.Value) {
panic("invalid Message.Set on " + string(m.Descriptor().FullName()))
}
-func (m aberrantMessage) Mutable(pref.FieldDescriptor) pref.Value {
+func (m aberrantMessage) Mutable(protoreflect.FieldDescriptor) protoreflect.Value {
panic("invalid Message.Mutable on " + string(m.Descriptor().FullName()))
}
-func (m aberrantMessage) NewField(pref.FieldDescriptor) pref.Value {
+func (m aberrantMessage) NewField(protoreflect.FieldDescriptor) protoreflect.Value {
panic("invalid Message.NewField on " + string(m.Descriptor().FullName()))
}
-func (m aberrantMessage) WhichOneof(pref.OneofDescriptor) pref.FieldDescriptor {
+func (m aberrantMessage) WhichOneof(protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
panic("invalid Message.WhichOneof descriptor on " + string(m.Descriptor().FullName()))
}
-func (m aberrantMessage) GetUnknown() pref.RawFields {
+func (m aberrantMessage) GetUnknown() protoreflect.RawFields {
return nil
}
-func (m aberrantMessage) SetUnknown(pref.RawFields) {
+func (m aberrantMessage) SetUnknown(protoreflect.RawFields) {
// SetUnknown discards its input on messages which don't support unknown field storage.
}
func (m aberrantMessage) IsValid() bool {
@@ -557,7 +555,7 @@ func (m aberrantMessage) IsValid() bool {
}
return false
}
-func (m aberrantMessage) ProtoMethods() *piface.Methods {
+func (m aberrantMessage) ProtoMethods() *protoiface.Methods {
return aberrantProtoMethods
}
func (m aberrantMessage) protoUnwrap() 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.go b/internal/impl/message.go
index a104e28e..4f5fb67a 100644
--- a/internal/impl/message.go
+++ b/internal/impl/message.go
@@ -14,8 +14,7 @@ import (
"google.golang.org/protobuf/internal/genid"
"google.golang.org/protobuf/reflect/protoreflect"
- pref "google.golang.org/protobuf/reflect/protoreflect"
- preg "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/reflect/protoregistry"
)
// MessageInfo provides protobuf related functionality for a given Go type
@@ -29,7 +28,7 @@ type MessageInfo struct {
GoReflectType reflect.Type // pointer to struct
// Desc is the underlying message descriptor type and must be populated.
- Desc pref.MessageDescriptor
+ Desc protoreflect.MessageDescriptor
// Exporter must be provided in a purego environment in order to provide
// access to unexported fields.
@@ -54,7 +53,7 @@ type exporter func(v interface{}, i int) interface{}
// is generated by our implementation of protoc-gen-go (for v2 and on).
// If it is unable to obtain a MessageInfo, it returns nil.
func getMessageInfo(mt reflect.Type) *MessageInfo {
- m, ok := reflect.Zero(mt).Interface().(pref.ProtoMessage)
+ m, ok := reflect.Zero(mt).Interface().(protoreflect.ProtoMessage)
if !ok {
return nil
}
@@ -97,7 +96,7 @@ func (mi *MessageInfo) initOnce() {
// getPointer returns the pointer for a message, which should be of
// the type of the MessageInfo. If the message is of a different type,
// it returns ok==false.
-func (mi *MessageInfo) getPointer(m pref.Message) (p pointer, ok bool) {
+func (mi *MessageInfo) getPointer(m protoreflect.Message) (p pointer, ok bool) {
switch m := m.(type) {
case *messageState:
return m.pointer(), m.messageInfo() == mi
@@ -134,10 +133,10 @@ type structInfo struct {
extensionOffset offset
extensionType reflect.Type
- fieldsByNumber map[pref.FieldNumber]reflect.StructField
- oneofsByName map[pref.Name]reflect.StructField
- oneofWrappersByType map[reflect.Type]pref.FieldNumber
- oneofWrappersByNumber map[pref.FieldNumber]reflect.Type
+ fieldsByNumber map[protoreflect.FieldNumber]reflect.StructField
+ oneofsByName map[protoreflect.Name]reflect.StructField
+ oneofWrappersByType map[reflect.Type]protoreflect.FieldNumber
+ oneofWrappersByNumber map[protoreflect.FieldNumber]reflect.Type
}
func (mi *MessageInfo) makeStructInfo(t reflect.Type) structInfo {
@@ -147,10 +146,10 @@ func (mi *MessageInfo) makeStructInfo(t reflect.Type) structInfo {
unknownOffset: invalidOffset,
extensionOffset: invalidOffset,
- fieldsByNumber: map[pref.FieldNumber]reflect.StructField{},
- oneofsByName: map[pref.Name]reflect.StructField{},
- oneofWrappersByType: map[reflect.Type]pref.FieldNumber{},
- oneofWrappersByNumber: map[pref.FieldNumber]reflect.Type{},
+ fieldsByNumber: map[protoreflect.FieldNumber]reflect.StructField{},
+ oneofsByName: map[protoreflect.Name]reflect.StructField{},
+ oneofWrappersByType: map[reflect.Type]protoreflect.FieldNumber{},
+ oneofWrappersByNumber: map[protoreflect.FieldNumber]reflect.Type{},
}
fieldLoop:
@@ -180,12 +179,12 @@ fieldLoop:
for _, s := range strings.Split(f.Tag.Get("protobuf"), ",") {
if len(s) > 0 && strings.Trim(s, "0123456789") == "" {
n, _ := strconv.ParseUint(s, 10, 64)
- si.fieldsByNumber[pref.FieldNumber(n)] = f
+ si.fieldsByNumber[protoreflect.FieldNumber(n)] = f
continue fieldLoop
}
}
if s := f.Tag.Get("protobuf_oneof"); len(s) > 0 {
- si.oneofsByName[pref.Name(s)] = f
+ si.oneofsByName[protoreflect.Name(s)] = f
continue fieldLoop
}
}
@@ -208,8 +207,8 @@ fieldLoop:
for _, s := range strings.Split(f.Tag.Get("protobuf"), ",") {
if len(s) > 0 && strings.Trim(s, "0123456789") == "" {
n, _ := strconv.ParseUint(s, 10, 64)
- si.oneofWrappersByType[tf] = pref.FieldNumber(n)
- si.oneofWrappersByNumber[pref.FieldNumber(n)] = tf
+ si.oneofWrappersByType[tf] = protoreflect.FieldNumber(n)
+ si.oneofWrappersByNumber[protoreflect.FieldNumber(n)] = tf
break
}
}
@@ -219,7 +218,11 @@ fieldLoop:
}
func (mi *MessageInfo) New() protoreflect.Message {
- return mi.MessageOf(reflect.New(mi.GoReflectType.Elem()).Interface())
+ m := reflect.New(mi.GoReflectType.Elem()).Interface()
+ if r, ok := m.(protoreflect.ProtoMessage); ok {
+ return r.ProtoReflect()
+ }
+ return mi.MessageOf(m)
}
func (mi *MessageInfo) Zero() protoreflect.Message {
return mi.MessageOf(reflect.Zero(mi.GoReflectType).Interface())
@@ -237,7 +240,7 @@ func (mi *MessageInfo) Message(i int) protoreflect.MessageType {
fd := mi.Desc.Fields().Get(i)
switch {
case fd.IsWeak():
- mt, _ := preg.GlobalTypes.FindMessageByName(fd.Message().FullName())
+ mt, _ := protoregistry.GlobalTypes.FindMessageByName(fd.Message().FullName())
return mt
case fd.IsMap():
return mapEntryType{fd.Message(), mi.fieldTypes[fd.Number()]}
diff --git a/internal/impl/message_reflect.go b/internal/impl/message_reflect.go
index 9488b726..d9ea010b 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 {
@@ -320,7 +320,6 @@ func (m *extensionMap) Mutable(xt pref.ExtensionType) pref.Value {
// in an allocation-free way without needing to have a shadow Go type generated
// for every message type. This technique only works using unsafe.
//
-//
// Example generated code:
//
// type M struct {
@@ -351,12 +350,11 @@ func (m *extensionMap) Mutable(xt pref.ExtensionType) pref.Value {
// It has access to the message info as its first field, and a pointer to the
// MessageState is identical to a pointer to the concrete message value.
//
-//
// Requirements:
-// • The type M must implement protoreflect.ProtoMessage.
-// • The address of m must not be nil.
-// • The address of m and the address of m.state must be equal,
-// even though they are different Go types.
+// - The type M must implement protoreflect.ProtoMessage.
+// - The address of m must not be nil.
+// - The address of m and the address of m.state must be equal,
+// even though they are different Go types.
type MessageState struct {
pragma.NoUnkeyedLiterals
pragma.DoNotCompare
@@ -368,8 +366,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 +385,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 +419,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 +428,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 +453,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 {