|
@@ -10,7 +10,7 @@ import (
|
|
|
|
|
|
"google.golang.org/protobuf/encoding/protowire"
|
|
"google.golang.org/protobuf/encoding/protowire"
|
|
"google.golang.org/protobuf/internal/strs"
|
|
"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.
|
|
// pointerCoderFuncs is a set of pointer encoding functions.
|
|
@@ -25,83 +25,83 @@ type pointerCoderFuncs struct {
|
|
|
|
|
|
// valueCoderFuncs is a set of protoreflect.Value encoding functions.
|
|
// valueCoderFuncs is a set of protoreflect.Value encoding functions.
|
|
type valueCoderFuncs struct {
|
|
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
|
|
// fieldCoder returns pointer functions for a field, used for operating on
|
|
// struct fields.
|
|
// struct fields.
|
|
-func fieldCoder(fd pref.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointerCoderFuncs) {
|
|
|
|
|
|
+func fieldCoder(fd protoreflect.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointerCoderFuncs) {
|
|
switch {
|
|
switch {
|
|
case fd.IsMap():
|
|
case fd.IsMap():
|
|
return encoderFuncsForMap(fd, ft)
|
|
return encoderFuncsForMap(fd, ft)
|
|
- case fd.Cardinality() == pref.Repeated && !fd.IsPacked():
|
|
|
|
|
|
+ case fd.Cardinality() == protoreflect.Repeated && !fd.IsPacked():
|
|
// Repeated fields (not packed).
|
|
// Repeated fields (not packed).
|
|
if ft.Kind() != reflect.Slice {
|
|
if ft.Kind() != reflect.Slice {
|
|
break
|
|
break
|
|
}
|
|
}
|
|
ft := ft.Elem()
|
|
ft := ft.Elem()
|
|
switch fd.Kind() {
|
|
switch fd.Kind() {
|
|
- case pref.BoolKind:
|
|
|
|
|
|
+ case protoreflect.BoolKind:
|
|
if ft.Kind() == reflect.Bool {
|
|
if ft.Kind() == reflect.Bool {
|
|
return nil, coderBoolSlice
|
|
return nil, coderBoolSlice
|
|
}
|
|
}
|
|
- case pref.EnumKind:
|
|
|
|
|
|
+ case protoreflect.EnumKind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderEnumSlice
|
|
return nil, coderEnumSlice
|
|
}
|
|
}
|
|
- case pref.Int32Kind:
|
|
|
|
|
|
+ case protoreflect.Int32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderInt32Slice
|
|
return nil, coderInt32Slice
|
|
}
|
|
}
|
|
- case pref.Sint32Kind:
|
|
|
|
|
|
+ case protoreflect.Sint32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderSint32Slice
|
|
return nil, coderSint32Slice
|
|
}
|
|
}
|
|
- case pref.Uint32Kind:
|
|
|
|
|
|
+ case protoreflect.Uint32Kind:
|
|
if ft.Kind() == reflect.Uint32 {
|
|
if ft.Kind() == reflect.Uint32 {
|
|
return nil, coderUint32Slice
|
|
return nil, coderUint32Slice
|
|
}
|
|
}
|
|
- case pref.Int64Kind:
|
|
|
|
|
|
+ case protoreflect.Int64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderInt64Slice
|
|
return nil, coderInt64Slice
|
|
}
|
|
}
|
|
- case pref.Sint64Kind:
|
|
|
|
|
|
+ case protoreflect.Sint64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderSint64Slice
|
|
return nil, coderSint64Slice
|
|
}
|
|
}
|
|
- case pref.Uint64Kind:
|
|
|
|
|
|
+ case protoreflect.Uint64Kind:
|
|
if ft.Kind() == reflect.Uint64 {
|
|
if ft.Kind() == reflect.Uint64 {
|
|
return nil, coderUint64Slice
|
|
return nil, coderUint64Slice
|
|
}
|
|
}
|
|
- case pref.Sfixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderSfixed32Slice
|
|
return nil, coderSfixed32Slice
|
|
}
|
|
}
|
|
- case pref.Fixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed32Kind:
|
|
if ft.Kind() == reflect.Uint32 {
|
|
if ft.Kind() == reflect.Uint32 {
|
|
return nil, coderFixed32Slice
|
|
return nil, coderFixed32Slice
|
|
}
|
|
}
|
|
- case pref.FloatKind:
|
|
|
|
|
|
+ case protoreflect.FloatKind:
|
|
if ft.Kind() == reflect.Float32 {
|
|
if ft.Kind() == reflect.Float32 {
|
|
return nil, coderFloatSlice
|
|
return nil, coderFloatSlice
|
|
}
|
|
}
|
|
- case pref.Sfixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderSfixed64Slice
|
|
return nil, coderSfixed64Slice
|
|
}
|
|
}
|
|
- case pref.Fixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed64Kind:
|
|
if ft.Kind() == reflect.Uint64 {
|
|
if ft.Kind() == reflect.Uint64 {
|
|
return nil, coderFixed64Slice
|
|
return nil, coderFixed64Slice
|
|
}
|
|
}
|
|
- case pref.DoubleKind:
|
|
|
|
|
|
+ case protoreflect.DoubleKind:
|
|
if ft.Kind() == reflect.Float64 {
|
|
if ft.Kind() == reflect.Float64 {
|
|
return nil, coderDoubleSlice
|
|
return nil, coderDoubleSlice
|
|
}
|
|
}
|
|
- case pref.StringKind:
|
|
|
|
|
|
+ case protoreflect.StringKind:
|
|
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
|
|
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
|
|
return nil, coderStringSliceValidateUTF8
|
|
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 {
|
|
if ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8 {
|
|
return nil, coderBytesSlice
|
|
return nil, coderBytesSlice
|
|
}
|
|
}
|
|
- case pref.BytesKind:
|
|
|
|
|
|
+ case protoreflect.BytesKind:
|
|
if ft.Kind() == reflect.String {
|
|
if ft.Kind() == reflect.String {
|
|
return nil, coderStringSlice
|
|
return nil, coderStringSlice
|
|
}
|
|
}
|
|
if ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8 {
|
|
if ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8 {
|
|
return nil, coderBytesSlice
|
|
return nil, coderBytesSlice
|
|
}
|
|
}
|
|
- case pref.MessageKind:
|
|
|
|
|
|
+ case protoreflect.MessageKind:
|
|
return getMessageInfo(ft), makeMessageSliceFieldCoder(fd, ft)
|
|
return getMessageInfo(ft), makeMessageSliceFieldCoder(fd, ft)
|
|
- case pref.GroupKind:
|
|
|
|
|
|
+ case protoreflect.GroupKind:
|
|
return getMessageInfo(ft), makeGroupSliceFieldCoder(fd, ft)
|
|
return getMessageInfo(ft), makeGroupSliceFieldCoder(fd, ft)
|
|
}
|
|
}
|
|
- case fd.Cardinality() == pref.Repeated && fd.IsPacked():
|
|
|
|
|
|
+ case fd.Cardinality() == protoreflect.Repeated && fd.IsPacked():
|
|
// Packed repeated fields.
|
|
// Packed repeated fields.
|
|
//
|
|
//
|
|
// Only repeated fields of primitive numeric types
|
|
// Only repeated fields of primitive numeric types
|
|
@@ -136,128 +136,128 @@ func fieldCoder(fd pref.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointer
|
|
}
|
|
}
|
|
ft := ft.Elem()
|
|
ft := ft.Elem()
|
|
switch fd.Kind() {
|
|
switch fd.Kind() {
|
|
- case pref.BoolKind:
|
|
|
|
|
|
+ case protoreflect.BoolKind:
|
|
if ft.Kind() == reflect.Bool {
|
|
if ft.Kind() == reflect.Bool {
|
|
return nil, coderBoolPackedSlice
|
|
return nil, coderBoolPackedSlice
|
|
}
|
|
}
|
|
- case pref.EnumKind:
|
|
|
|
|
|
+ case protoreflect.EnumKind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderEnumPackedSlice
|
|
return nil, coderEnumPackedSlice
|
|
}
|
|
}
|
|
- case pref.Int32Kind:
|
|
|
|
|
|
+ case protoreflect.Int32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderInt32PackedSlice
|
|
return nil, coderInt32PackedSlice
|
|
}
|
|
}
|
|
- case pref.Sint32Kind:
|
|
|
|
|
|
+ case protoreflect.Sint32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderSint32PackedSlice
|
|
return nil, coderSint32PackedSlice
|
|
}
|
|
}
|
|
- case pref.Uint32Kind:
|
|
|
|
|
|
+ case protoreflect.Uint32Kind:
|
|
if ft.Kind() == reflect.Uint32 {
|
|
if ft.Kind() == reflect.Uint32 {
|
|
return nil, coderUint32PackedSlice
|
|
return nil, coderUint32PackedSlice
|
|
}
|
|
}
|
|
- case pref.Int64Kind:
|
|
|
|
|
|
+ case protoreflect.Int64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderInt64PackedSlice
|
|
return nil, coderInt64PackedSlice
|
|
}
|
|
}
|
|
- case pref.Sint64Kind:
|
|
|
|
|
|
+ case protoreflect.Sint64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderSint64PackedSlice
|
|
return nil, coderSint64PackedSlice
|
|
}
|
|
}
|
|
- case pref.Uint64Kind:
|
|
|
|
|
|
+ case protoreflect.Uint64Kind:
|
|
if ft.Kind() == reflect.Uint64 {
|
|
if ft.Kind() == reflect.Uint64 {
|
|
return nil, coderUint64PackedSlice
|
|
return nil, coderUint64PackedSlice
|
|
}
|
|
}
|
|
- case pref.Sfixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderSfixed32PackedSlice
|
|
return nil, coderSfixed32PackedSlice
|
|
}
|
|
}
|
|
- case pref.Fixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed32Kind:
|
|
if ft.Kind() == reflect.Uint32 {
|
|
if ft.Kind() == reflect.Uint32 {
|
|
return nil, coderFixed32PackedSlice
|
|
return nil, coderFixed32PackedSlice
|
|
}
|
|
}
|
|
- case pref.FloatKind:
|
|
|
|
|
|
+ case protoreflect.FloatKind:
|
|
if ft.Kind() == reflect.Float32 {
|
|
if ft.Kind() == reflect.Float32 {
|
|
return nil, coderFloatPackedSlice
|
|
return nil, coderFloatPackedSlice
|
|
}
|
|
}
|
|
- case pref.Sfixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderSfixed64PackedSlice
|
|
return nil, coderSfixed64PackedSlice
|
|
}
|
|
}
|
|
- case pref.Fixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed64Kind:
|
|
if ft.Kind() == reflect.Uint64 {
|
|
if ft.Kind() == reflect.Uint64 {
|
|
return nil, coderFixed64PackedSlice
|
|
return nil, coderFixed64PackedSlice
|
|
}
|
|
}
|
|
- case pref.DoubleKind:
|
|
|
|
|
|
+ case protoreflect.DoubleKind:
|
|
if ft.Kind() == reflect.Float64 {
|
|
if ft.Kind() == reflect.Float64 {
|
|
return nil, coderDoublePackedSlice
|
|
return nil, coderDoublePackedSlice
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- case fd.Kind() == pref.MessageKind:
|
|
|
|
|
|
+ case fd.Kind() == protoreflect.MessageKind:
|
|
return getMessageInfo(ft), makeMessageFieldCoder(fd, ft)
|
|
return getMessageInfo(ft), makeMessageFieldCoder(fd, ft)
|
|
- case fd.Kind() == pref.GroupKind:
|
|
|
|
|
|
+ case fd.Kind() == protoreflect.GroupKind:
|
|
return getMessageInfo(ft), makeGroupFieldCoder(fd, ft)
|
|
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,
|
|
// Populated oneof fields always encode even if set to the zero value,
|
|
// which normally are not encoded in proto3.
|
|
// which normally are not encoded in proto3.
|
|
switch fd.Kind() {
|
|
switch fd.Kind() {
|
|
- case pref.BoolKind:
|
|
|
|
|
|
+ case protoreflect.BoolKind:
|
|
if ft.Kind() == reflect.Bool {
|
|
if ft.Kind() == reflect.Bool {
|
|
return nil, coderBoolNoZero
|
|
return nil, coderBoolNoZero
|
|
}
|
|
}
|
|
- case pref.EnumKind:
|
|
|
|
|
|
+ case protoreflect.EnumKind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderEnumNoZero
|
|
return nil, coderEnumNoZero
|
|
}
|
|
}
|
|
- case pref.Int32Kind:
|
|
|
|
|
|
+ case protoreflect.Int32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderInt32NoZero
|
|
return nil, coderInt32NoZero
|
|
}
|
|
}
|
|
- case pref.Sint32Kind:
|
|
|
|
|
|
+ case protoreflect.Sint32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderSint32NoZero
|
|
return nil, coderSint32NoZero
|
|
}
|
|
}
|
|
- case pref.Uint32Kind:
|
|
|
|
|
|
+ case protoreflect.Uint32Kind:
|
|
if ft.Kind() == reflect.Uint32 {
|
|
if ft.Kind() == reflect.Uint32 {
|
|
return nil, coderUint32NoZero
|
|
return nil, coderUint32NoZero
|
|
}
|
|
}
|
|
- case pref.Int64Kind:
|
|
|
|
|
|
+ case protoreflect.Int64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderInt64NoZero
|
|
return nil, coderInt64NoZero
|
|
}
|
|
}
|
|
- case pref.Sint64Kind:
|
|
|
|
|
|
+ case protoreflect.Sint64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderSint64NoZero
|
|
return nil, coderSint64NoZero
|
|
}
|
|
}
|
|
- case pref.Uint64Kind:
|
|
|
|
|
|
+ case protoreflect.Uint64Kind:
|
|
if ft.Kind() == reflect.Uint64 {
|
|
if ft.Kind() == reflect.Uint64 {
|
|
return nil, coderUint64NoZero
|
|
return nil, coderUint64NoZero
|
|
}
|
|
}
|
|
- case pref.Sfixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderSfixed32NoZero
|
|
return nil, coderSfixed32NoZero
|
|
}
|
|
}
|
|
- case pref.Fixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed32Kind:
|
|
if ft.Kind() == reflect.Uint32 {
|
|
if ft.Kind() == reflect.Uint32 {
|
|
return nil, coderFixed32NoZero
|
|
return nil, coderFixed32NoZero
|
|
}
|
|
}
|
|
- case pref.FloatKind:
|
|
|
|
|
|
+ case protoreflect.FloatKind:
|
|
if ft.Kind() == reflect.Float32 {
|
|
if ft.Kind() == reflect.Float32 {
|
|
return nil, coderFloatNoZero
|
|
return nil, coderFloatNoZero
|
|
}
|
|
}
|
|
- case pref.Sfixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderSfixed64NoZero
|
|
return nil, coderSfixed64NoZero
|
|
}
|
|
}
|
|
- case pref.Fixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed64Kind:
|
|
if ft.Kind() == reflect.Uint64 {
|
|
if ft.Kind() == reflect.Uint64 {
|
|
return nil, coderFixed64NoZero
|
|
return nil, coderFixed64NoZero
|
|
}
|
|
}
|
|
- case pref.DoubleKind:
|
|
|
|
|
|
+ case protoreflect.DoubleKind:
|
|
if ft.Kind() == reflect.Float64 {
|
|
if ft.Kind() == reflect.Float64 {
|
|
return nil, coderDoubleNoZero
|
|
return nil, coderDoubleNoZero
|
|
}
|
|
}
|
|
- case pref.StringKind:
|
|
|
|
|
|
+ case protoreflect.StringKind:
|
|
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
|
|
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
|
|
return nil, coderStringNoZeroValidateUTF8
|
|
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 {
|
|
if ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8 {
|
|
return nil, coderBytesNoZero
|
|
return nil, coderBytesNoZero
|
|
}
|
|
}
|
|
- case pref.BytesKind:
|
|
|
|
|
|
+ case protoreflect.BytesKind:
|
|
if ft.Kind() == reflect.String {
|
|
if ft.Kind() == reflect.String {
|
|
return nil, coderStringNoZero
|
|
return nil, coderStringNoZero
|
|
}
|
|
}
|
|
@@ -281,133 +281,133 @@ func fieldCoder(fd pref.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointer
|
|
case ft.Kind() == reflect.Ptr:
|
|
case ft.Kind() == reflect.Ptr:
|
|
ft := ft.Elem()
|
|
ft := ft.Elem()
|
|
switch fd.Kind() {
|
|
switch fd.Kind() {
|
|
- case pref.BoolKind:
|
|
|
|
|
|
+ case protoreflect.BoolKind:
|
|
if ft.Kind() == reflect.Bool {
|
|
if ft.Kind() == reflect.Bool {
|
|
return nil, coderBoolPtr
|
|
return nil, coderBoolPtr
|
|
}
|
|
}
|
|
- case pref.EnumKind:
|
|
|
|
|
|
+ case protoreflect.EnumKind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderEnumPtr
|
|
return nil, coderEnumPtr
|
|
}
|
|
}
|
|
- case pref.Int32Kind:
|
|
|
|
|
|
+ case protoreflect.Int32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderInt32Ptr
|
|
return nil, coderInt32Ptr
|
|
}
|
|
}
|
|
- case pref.Sint32Kind:
|
|
|
|
|
|
+ case protoreflect.Sint32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderSint32Ptr
|
|
return nil, coderSint32Ptr
|
|
}
|
|
}
|
|
- case pref.Uint32Kind:
|
|
|
|
|
|
+ case protoreflect.Uint32Kind:
|
|
if ft.Kind() == reflect.Uint32 {
|
|
if ft.Kind() == reflect.Uint32 {
|
|
return nil, coderUint32Ptr
|
|
return nil, coderUint32Ptr
|
|
}
|
|
}
|
|
- case pref.Int64Kind:
|
|
|
|
|
|
+ case protoreflect.Int64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderInt64Ptr
|
|
return nil, coderInt64Ptr
|
|
}
|
|
}
|
|
- case pref.Sint64Kind:
|
|
|
|
|
|
+ case protoreflect.Sint64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderSint64Ptr
|
|
return nil, coderSint64Ptr
|
|
}
|
|
}
|
|
- case pref.Uint64Kind:
|
|
|
|
|
|
+ case protoreflect.Uint64Kind:
|
|
if ft.Kind() == reflect.Uint64 {
|
|
if ft.Kind() == reflect.Uint64 {
|
|
return nil, coderUint64Ptr
|
|
return nil, coderUint64Ptr
|
|
}
|
|
}
|
|
- case pref.Sfixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderSfixed32Ptr
|
|
return nil, coderSfixed32Ptr
|
|
}
|
|
}
|
|
- case pref.Fixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed32Kind:
|
|
if ft.Kind() == reflect.Uint32 {
|
|
if ft.Kind() == reflect.Uint32 {
|
|
return nil, coderFixed32Ptr
|
|
return nil, coderFixed32Ptr
|
|
}
|
|
}
|
|
- case pref.FloatKind:
|
|
|
|
|
|
+ case protoreflect.FloatKind:
|
|
if ft.Kind() == reflect.Float32 {
|
|
if ft.Kind() == reflect.Float32 {
|
|
return nil, coderFloatPtr
|
|
return nil, coderFloatPtr
|
|
}
|
|
}
|
|
- case pref.Sfixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderSfixed64Ptr
|
|
return nil, coderSfixed64Ptr
|
|
}
|
|
}
|
|
- case pref.Fixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed64Kind:
|
|
if ft.Kind() == reflect.Uint64 {
|
|
if ft.Kind() == reflect.Uint64 {
|
|
return nil, coderFixed64Ptr
|
|
return nil, coderFixed64Ptr
|
|
}
|
|
}
|
|
- case pref.DoubleKind:
|
|
|
|
|
|
+ case protoreflect.DoubleKind:
|
|
if ft.Kind() == reflect.Float64 {
|
|
if ft.Kind() == reflect.Float64 {
|
|
return nil, coderDoublePtr
|
|
return nil, coderDoublePtr
|
|
}
|
|
}
|
|
- case pref.StringKind:
|
|
|
|
|
|
+ case protoreflect.StringKind:
|
|
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
|
|
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
|
|
return nil, coderStringPtrValidateUTF8
|
|
return nil, coderStringPtrValidateUTF8
|
|
}
|
|
}
|
|
if ft.Kind() == reflect.String {
|
|
if ft.Kind() == reflect.String {
|
|
return nil, coderStringPtr
|
|
return nil, coderStringPtr
|
|
}
|
|
}
|
|
- case pref.BytesKind:
|
|
|
|
|
|
+ case protoreflect.BytesKind:
|
|
if ft.Kind() == reflect.String {
|
|
if ft.Kind() == reflect.String {
|
|
return nil, coderStringPtr
|
|
return nil, coderStringPtr
|
|
}
|
|
}
|
|
}
|
|
}
|
|
default:
|
|
default:
|
|
switch fd.Kind() {
|
|
switch fd.Kind() {
|
|
- case pref.BoolKind:
|
|
|
|
|
|
+ case protoreflect.BoolKind:
|
|
if ft.Kind() == reflect.Bool {
|
|
if ft.Kind() == reflect.Bool {
|
|
return nil, coderBool
|
|
return nil, coderBool
|
|
}
|
|
}
|
|
- case pref.EnumKind:
|
|
|
|
|
|
+ case protoreflect.EnumKind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderEnum
|
|
return nil, coderEnum
|
|
}
|
|
}
|
|
- case pref.Int32Kind:
|
|
|
|
|
|
+ case protoreflect.Int32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderInt32
|
|
return nil, coderInt32
|
|
}
|
|
}
|
|
- case pref.Sint32Kind:
|
|
|
|
|
|
+ case protoreflect.Sint32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderSint32
|
|
return nil, coderSint32
|
|
}
|
|
}
|
|
- case pref.Uint32Kind:
|
|
|
|
|
|
+ case protoreflect.Uint32Kind:
|
|
if ft.Kind() == reflect.Uint32 {
|
|
if ft.Kind() == reflect.Uint32 {
|
|
return nil, coderUint32
|
|
return nil, coderUint32
|
|
}
|
|
}
|
|
- case pref.Int64Kind:
|
|
|
|
|
|
+ case protoreflect.Int64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderInt64
|
|
return nil, coderInt64
|
|
}
|
|
}
|
|
- case pref.Sint64Kind:
|
|
|
|
|
|
+ case protoreflect.Sint64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderSint64
|
|
return nil, coderSint64
|
|
}
|
|
}
|
|
- case pref.Uint64Kind:
|
|
|
|
|
|
+ case protoreflect.Uint64Kind:
|
|
if ft.Kind() == reflect.Uint64 {
|
|
if ft.Kind() == reflect.Uint64 {
|
|
return nil, coderUint64
|
|
return nil, coderUint64
|
|
}
|
|
}
|
|
- case pref.Sfixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed32Kind:
|
|
if ft.Kind() == reflect.Int32 {
|
|
if ft.Kind() == reflect.Int32 {
|
|
return nil, coderSfixed32
|
|
return nil, coderSfixed32
|
|
}
|
|
}
|
|
- case pref.Fixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed32Kind:
|
|
if ft.Kind() == reflect.Uint32 {
|
|
if ft.Kind() == reflect.Uint32 {
|
|
return nil, coderFixed32
|
|
return nil, coderFixed32
|
|
}
|
|
}
|
|
- case pref.FloatKind:
|
|
|
|
|
|
+ case protoreflect.FloatKind:
|
|
if ft.Kind() == reflect.Float32 {
|
|
if ft.Kind() == reflect.Float32 {
|
|
return nil, coderFloat
|
|
return nil, coderFloat
|
|
}
|
|
}
|
|
- case pref.Sfixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed64Kind:
|
|
if ft.Kind() == reflect.Int64 {
|
|
if ft.Kind() == reflect.Int64 {
|
|
return nil, coderSfixed64
|
|
return nil, coderSfixed64
|
|
}
|
|
}
|
|
- case pref.Fixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed64Kind:
|
|
if ft.Kind() == reflect.Uint64 {
|
|
if ft.Kind() == reflect.Uint64 {
|
|
return nil, coderFixed64
|
|
return nil, coderFixed64
|
|
}
|
|
}
|
|
- case pref.DoubleKind:
|
|
|
|
|
|
+ case protoreflect.DoubleKind:
|
|
if ft.Kind() == reflect.Float64 {
|
|
if ft.Kind() == reflect.Float64 {
|
|
return nil, coderDouble
|
|
return nil, coderDouble
|
|
}
|
|
}
|
|
- case pref.StringKind:
|
|
|
|
|
|
+ case protoreflect.StringKind:
|
|
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
|
|
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
|
|
return nil, coderStringValidateUTF8
|
|
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 {
|
|
if ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8 {
|
|
return nil, coderBytes
|
|
return nil, coderBytes
|
|
}
|
|
}
|
|
- case pref.BytesKind:
|
|
|
|
|
|
+ case protoreflect.BytesKind:
|
|
if ft.Kind() == reflect.String {
|
|
if ft.Kind() == reflect.String {
|
|
return nil, coderString
|
|
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
|
|
// encoderFuncsForValue returns value functions for a field, used for
|
|
// extension values and map encoding.
|
|
// extension values and map encoding.
|
|
-func encoderFuncsForValue(fd pref.FieldDescriptor) valueCoderFuncs {
|
|
|
|
|
|
+func encoderFuncsForValue(fd protoreflect.FieldDescriptor) valueCoderFuncs {
|
|
switch {
|
|
switch {
|
|
- case fd.Cardinality() == pref.Repeated && !fd.IsPacked():
|
|
|
|
|
|
+ case fd.Cardinality() == protoreflect.Repeated && !fd.IsPacked():
|
|
switch fd.Kind() {
|
|
switch fd.Kind() {
|
|
- case pref.BoolKind:
|
|
|
|
|
|
+ case protoreflect.BoolKind:
|
|
return coderBoolSliceValue
|
|
return coderBoolSliceValue
|
|
- case pref.EnumKind:
|
|
|
|
|
|
+ case protoreflect.EnumKind:
|
|
return coderEnumSliceValue
|
|
return coderEnumSliceValue
|
|
- case pref.Int32Kind:
|
|
|
|
|
|
+ case protoreflect.Int32Kind:
|
|
return coderInt32SliceValue
|
|
return coderInt32SliceValue
|
|
- case pref.Sint32Kind:
|
|
|
|
|
|
+ case protoreflect.Sint32Kind:
|
|
return coderSint32SliceValue
|
|
return coderSint32SliceValue
|
|
- case pref.Uint32Kind:
|
|
|
|
|
|
+ case protoreflect.Uint32Kind:
|
|
return coderUint32SliceValue
|
|
return coderUint32SliceValue
|
|
- case pref.Int64Kind:
|
|
|
|
|
|
+ case protoreflect.Int64Kind:
|
|
return coderInt64SliceValue
|
|
return coderInt64SliceValue
|
|
- case pref.Sint64Kind:
|
|
|
|
|
|
+ case protoreflect.Sint64Kind:
|
|
return coderSint64SliceValue
|
|
return coderSint64SliceValue
|
|
- case pref.Uint64Kind:
|
|
|
|
|
|
+ case protoreflect.Uint64Kind:
|
|
return coderUint64SliceValue
|
|
return coderUint64SliceValue
|
|
- case pref.Sfixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed32Kind:
|
|
return coderSfixed32SliceValue
|
|
return coderSfixed32SliceValue
|
|
- case pref.Fixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed32Kind:
|
|
return coderFixed32SliceValue
|
|
return coderFixed32SliceValue
|
|
- case pref.FloatKind:
|
|
|
|
|
|
+ case protoreflect.FloatKind:
|
|
return coderFloatSliceValue
|
|
return coderFloatSliceValue
|
|
- case pref.Sfixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed64Kind:
|
|
return coderSfixed64SliceValue
|
|
return coderSfixed64SliceValue
|
|
- case pref.Fixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed64Kind:
|
|
return coderFixed64SliceValue
|
|
return coderFixed64SliceValue
|
|
- case pref.DoubleKind:
|
|
|
|
|
|
+ case protoreflect.DoubleKind:
|
|
return coderDoubleSliceValue
|
|
return coderDoubleSliceValue
|
|
- case pref.StringKind:
|
|
|
|
|
|
+ case protoreflect.StringKind:
|
|
// We don't have a UTF-8 validating coder for repeated string fields.
|
|
// We don't have a UTF-8 validating coder for repeated string fields.
|
|
// Value coders are used for extensions and maps.
|
|
// Value coders are used for extensions and maps.
|
|
// Extensions are never proto3, and maps never contain lists.
|
|
// Extensions are never proto3, and maps never contain lists.
|
|
return coderStringSliceValue
|
|
return coderStringSliceValue
|
|
- case pref.BytesKind:
|
|
|
|
|
|
+ case protoreflect.BytesKind:
|
|
return coderBytesSliceValue
|
|
return coderBytesSliceValue
|
|
- case pref.MessageKind:
|
|
|
|
|
|
+ case protoreflect.MessageKind:
|
|
return coderMessageSliceValue
|
|
return coderMessageSliceValue
|
|
- case pref.GroupKind:
|
|
|
|
|
|
+ case protoreflect.GroupKind:
|
|
return coderGroupSliceValue
|
|
return coderGroupSliceValue
|
|
}
|
|
}
|
|
- case fd.Cardinality() == pref.Repeated && fd.IsPacked():
|
|
|
|
|
|
+ case fd.Cardinality() == protoreflect.Repeated && fd.IsPacked():
|
|
switch fd.Kind() {
|
|
switch fd.Kind() {
|
|
- case pref.BoolKind:
|
|
|
|
|
|
+ case protoreflect.BoolKind:
|
|
return coderBoolPackedSliceValue
|
|
return coderBoolPackedSliceValue
|
|
- case pref.EnumKind:
|
|
|
|
|
|
+ case protoreflect.EnumKind:
|
|
return coderEnumPackedSliceValue
|
|
return coderEnumPackedSliceValue
|
|
- case pref.Int32Kind:
|
|
|
|
|
|
+ case protoreflect.Int32Kind:
|
|
return coderInt32PackedSliceValue
|
|
return coderInt32PackedSliceValue
|
|
- case pref.Sint32Kind:
|
|
|
|
|
|
+ case protoreflect.Sint32Kind:
|
|
return coderSint32PackedSliceValue
|
|
return coderSint32PackedSliceValue
|
|
- case pref.Uint32Kind:
|
|
|
|
|
|
+ case protoreflect.Uint32Kind:
|
|
return coderUint32PackedSliceValue
|
|
return coderUint32PackedSliceValue
|
|
- case pref.Int64Kind:
|
|
|
|
|
|
+ case protoreflect.Int64Kind:
|
|
return coderInt64PackedSliceValue
|
|
return coderInt64PackedSliceValue
|
|
- case pref.Sint64Kind:
|
|
|
|
|
|
+ case protoreflect.Sint64Kind:
|
|
return coderSint64PackedSliceValue
|
|
return coderSint64PackedSliceValue
|
|
- case pref.Uint64Kind:
|
|
|
|
|
|
+ case protoreflect.Uint64Kind:
|
|
return coderUint64PackedSliceValue
|
|
return coderUint64PackedSliceValue
|
|
- case pref.Sfixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed32Kind:
|
|
return coderSfixed32PackedSliceValue
|
|
return coderSfixed32PackedSliceValue
|
|
- case pref.Fixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed32Kind:
|
|
return coderFixed32PackedSliceValue
|
|
return coderFixed32PackedSliceValue
|
|
- case pref.FloatKind:
|
|
|
|
|
|
+ case protoreflect.FloatKind:
|
|
return coderFloatPackedSliceValue
|
|
return coderFloatPackedSliceValue
|
|
- case pref.Sfixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed64Kind:
|
|
return coderSfixed64PackedSliceValue
|
|
return coderSfixed64PackedSliceValue
|
|
- case pref.Fixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed64Kind:
|
|
return coderFixed64PackedSliceValue
|
|
return coderFixed64PackedSliceValue
|
|
- case pref.DoubleKind:
|
|
|
|
|
|
+ case protoreflect.DoubleKind:
|
|
return coderDoublePackedSliceValue
|
|
return coderDoublePackedSliceValue
|
|
}
|
|
}
|
|
default:
|
|
default:
|
|
switch fd.Kind() {
|
|
switch fd.Kind() {
|
|
default:
|
|
default:
|
|
- case pref.BoolKind:
|
|
|
|
|
|
+ case protoreflect.BoolKind:
|
|
return coderBoolValue
|
|
return coderBoolValue
|
|
- case pref.EnumKind:
|
|
|
|
|
|
+ case protoreflect.EnumKind:
|
|
return coderEnumValue
|
|
return coderEnumValue
|
|
- case pref.Int32Kind:
|
|
|
|
|
|
+ case protoreflect.Int32Kind:
|
|
return coderInt32Value
|
|
return coderInt32Value
|
|
- case pref.Sint32Kind:
|
|
|
|
|
|
+ case protoreflect.Sint32Kind:
|
|
return coderSint32Value
|
|
return coderSint32Value
|
|
- case pref.Uint32Kind:
|
|
|
|
|
|
+ case protoreflect.Uint32Kind:
|
|
return coderUint32Value
|
|
return coderUint32Value
|
|
- case pref.Int64Kind:
|
|
|
|
|
|
+ case protoreflect.Int64Kind:
|
|
return coderInt64Value
|
|
return coderInt64Value
|
|
- case pref.Sint64Kind:
|
|
|
|
|
|
+ case protoreflect.Sint64Kind:
|
|
return coderSint64Value
|
|
return coderSint64Value
|
|
- case pref.Uint64Kind:
|
|
|
|
|
|
+ case protoreflect.Uint64Kind:
|
|
return coderUint64Value
|
|
return coderUint64Value
|
|
- case pref.Sfixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed32Kind:
|
|
return coderSfixed32Value
|
|
return coderSfixed32Value
|
|
- case pref.Fixed32Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed32Kind:
|
|
return coderFixed32Value
|
|
return coderFixed32Value
|
|
- case pref.FloatKind:
|
|
|
|
|
|
+ case protoreflect.FloatKind:
|
|
return coderFloatValue
|
|
return coderFloatValue
|
|
- case pref.Sfixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Sfixed64Kind:
|
|
return coderSfixed64Value
|
|
return coderSfixed64Value
|
|
- case pref.Fixed64Kind:
|
|
|
|
|
|
+ case protoreflect.Fixed64Kind:
|
|
return coderFixed64Value
|
|
return coderFixed64Value
|
|
- case pref.DoubleKind:
|
|
|
|
|
|
+ case protoreflect.DoubleKind:
|
|
return coderDoubleValue
|
|
return coderDoubleValue
|
|
- case pref.StringKind:
|
|
|
|
|
|
+ case protoreflect.StringKind:
|
|
if strs.EnforceUTF8(fd) {
|
|
if strs.EnforceUTF8(fd) {
|
|
return coderStringValueValidateUTF8
|
|
return coderStringValueValidateUTF8
|
|
}
|
|
}
|
|
return coderStringValue
|
|
return coderStringValue
|
|
- case pref.BytesKind:
|
|
|
|
|
|
+ case protoreflect.BytesKind:
|
|
return coderBytesValue
|
|
return coderBytesValue
|
|
- case pref.MessageKind:
|
|
|
|
|
|
+ case protoreflect.MessageKind:
|
|
return coderMessageValue
|
|
return coderMessageValue
|
|
- case pref.GroupKind:
|
|
|
|
|
|
+ case protoreflect.GroupKind:
|
|
return coderGroupValue
|
|
return coderGroupValue
|
|
}
|
|
}
|
|
}
|
|
}
|