This commit is contained in:
3
vendor/google.golang.org/protobuf/internal/impl/codec_message_opaque.go
generated
vendored
3
vendor/google.golang.org/protobuf/internal/impl/codec_message_opaque.go
generated
vendored
@ -11,6 +11,7 @@ import (
|
||||
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
"google.golang.org/protobuf/internal/encoding/messageset"
|
||||
"google.golang.org/protobuf/internal/filedesc"
|
||||
"google.golang.org/protobuf/internal/order"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
piface "google.golang.org/protobuf/runtime/protoiface"
|
||||
@ -80,7 +81,7 @@ func (mi *MessageInfo) makeOpaqueCoderMethods(t reflect.Type, si opaqueStructInf
|
||||
// permit us to skip over definitely-unset fields at marshal time.
|
||||
|
||||
var hasPresence bool
|
||||
hasPresence, cf.isLazy = usePresenceForField(si, fd)
|
||||
hasPresence, cf.isLazy = filedesc.UsePresenceForField(fd)
|
||||
|
||||
if hasPresence {
|
||||
cf.presenceIndex, mi.presenceSize = presenceIndex(mi.Desc, fd)
|
||||
|
45
vendor/google.golang.org/protobuf/internal/impl/message_opaque.go
generated
vendored
45
vendor/google.golang.org/protobuf/internal/impl/message_opaque.go
generated
vendored
@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
"google.golang.org/protobuf/internal/filedesc"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
@ -53,7 +54,7 @@ func opaqueInitHook(mi *MessageInfo) bool {
|
||||
fd := fds.Get(i)
|
||||
fs := si.fieldsByNumber[fd.Number()]
|
||||
var fi fieldInfo
|
||||
usePresence, _ := usePresenceForField(si, fd)
|
||||
usePresence, _ := filedesc.UsePresenceForField(fd)
|
||||
|
||||
switch {
|
||||
case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic():
|
||||
@ -343,17 +344,15 @@ func (mi *MessageInfo) fieldInfoForMessageListOpaqueNoPresence(si opaqueStructIn
|
||||
if p.IsNil() {
|
||||
return false
|
||||
}
|
||||
sp := p.Apply(fieldOffset).AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if rv.IsNil() {
|
||||
return false
|
||||
}
|
||||
rv := sp.AsValueOf(fs.Type.Elem())
|
||||
return rv.Elem().Len() > 0
|
||||
},
|
||||
clear: func(p pointer) {
|
||||
sp := p.Apply(fieldOffset).AtomicGetPointer()
|
||||
if !sp.IsNil() {
|
||||
rv := sp.AsValueOf(fs.Type.Elem())
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if !rv.IsNil() {
|
||||
rv.Elem().Set(reflect.Zero(rv.Type().Elem()))
|
||||
}
|
||||
},
|
||||
@ -361,11 +360,10 @@ func (mi *MessageInfo) fieldInfoForMessageListOpaqueNoPresence(si opaqueStructIn
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
sp := p.Apply(fieldOffset).AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if rv.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
rv := sp.AsValueOf(fs.Type.Elem())
|
||||
if rv.Elem().Len() == 0 {
|
||||
return conv.Zero()
|
||||
}
|
||||
@ -598,30 +596,3 @@ func (mi *MessageInfo) clearPresent(p pointer, index uint32) {
|
||||
func (mi *MessageInfo) present(p pointer, index uint32) bool {
|
||||
return p.Apply(mi.presenceOffset).PresenceInfo().Present(index)
|
||||
}
|
||||
|
||||
// usePresenceForField implements the somewhat intricate logic of when
|
||||
// the presence bitmap is used for a field. The main logic is that a
|
||||
// field that is optional or that can be lazy will use the presence
|
||||
// bit, but for proto2, also maps have a presence bit. It also records
|
||||
// if the field can ever be lazy, which is true if we have a
|
||||
// lazyOffset and the field is a message or a slice of messages. A
|
||||
// field that is lazy will always need a presence bit. Oneofs are not
|
||||
// lazy and do not use presence, unless they are a synthetic oneof,
|
||||
// which is a proto3 optional field. For proto3 optionals, we use the
|
||||
// presence and they can also be lazy when applicable (a message).
|
||||
func usePresenceForField(si opaqueStructInfo, fd protoreflect.FieldDescriptor) (usePresence, canBeLazy bool) {
|
||||
hasLazyField := fd.(interface{ IsLazy() bool }).IsLazy()
|
||||
|
||||
// Non-oneof scalar fields with explicit field presence use the presence array.
|
||||
usesPresenceArray := fd.HasPresence() && fd.Message() == nil && (fd.ContainingOneof() == nil || fd.ContainingOneof().IsSynthetic())
|
||||
switch {
|
||||
case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic():
|
||||
return false, false
|
||||
case fd.IsMap():
|
||||
return false, false
|
||||
case fd.Kind() == protoreflect.MessageKind || fd.Kind() == protoreflect.GroupKind:
|
||||
return hasLazyField, hasLazyField
|
||||
default:
|
||||
return usesPresenceArray || (hasLazyField && fd.HasPresence()), false
|
||||
}
|
||||
}
|
||||
|
3
vendor/google.golang.org/protobuf/internal/impl/presence.go
generated
vendored
3
vendor/google.golang.org/protobuf/internal/impl/presence.go
generated
vendored
@ -32,9 +32,6 @@ func (p presence) toElem(num uint32) (ret *uint32) {
|
||||
|
||||
// Present checks for the presence of a specific field number in a presence set.
|
||||
func (p presence) Present(num uint32) bool {
|
||||
if p.P == nil {
|
||||
return false
|
||||
}
|
||||
return Export{}.Present(p.toElem(num), num)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user