mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-03-09 13:13:32 +00:00
all: plumb the lazy option into filedesc.Field and .Extension
The IsLazy() method is intentionally not added to the protoreflect.FieldDescriptor interface because users should not need it. The Go Protobuf runtime will use type assertion to dynamically call the method. There is no change in behavior, this is preparation only. Change-Id: I4500c17f5edd1bdc40447eb89bff115b4e8eab06 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/596539 Reviewed-by: Chressie Himpel <chressie@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
df3bd63b9c
commit
b46f280f97
@ -258,6 +258,7 @@ type (
|
||||
StringName stringName
|
||||
IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto
|
||||
IsWeak bool // promoted from google.protobuf.FieldOptions
|
||||
IsLazy bool // promoted from google.protobuf.FieldOptions
|
||||
Default defaultValue
|
||||
ContainingOneof protoreflect.OneofDescriptor // must be consistent with Message.Oneofs.Fields
|
||||
Enum protoreflect.EnumDescriptor
|
||||
@ -351,6 +352,7 @@ func (fd *Field) IsPacked() bool {
|
||||
}
|
||||
func (fd *Field) IsExtension() bool { return false }
|
||||
func (fd *Field) IsWeak() bool { return fd.L1.IsWeak }
|
||||
func (fd *Field) IsLazy() bool { return fd.L1.IsLazy }
|
||||
func (fd *Field) IsList() bool { return fd.Cardinality() == protoreflect.Repeated && !fd.IsMap() }
|
||||
func (fd *Field) IsMap() bool { return fd.Message() != nil && fd.Message().IsMapEntry() }
|
||||
func (fd *Field) MapKey() protoreflect.FieldDescriptor {
|
||||
@ -425,6 +427,7 @@ type (
|
||||
Extendee protoreflect.MessageDescriptor
|
||||
Cardinality protoreflect.Cardinality
|
||||
Kind protoreflect.Kind
|
||||
IsLazy bool
|
||||
EditionFeatures EditionFeatures
|
||||
}
|
||||
ExtensionL2 struct {
|
||||
@ -465,6 +468,7 @@ func (xd *Extension) IsPacked() bool {
|
||||
}
|
||||
func (xd *Extension) IsExtension() bool { return true }
|
||||
func (xd *Extension) IsWeak() bool { return false }
|
||||
func (xd *Extension) IsLazy() bool { return xd.L1.IsLazy }
|
||||
func (xd *Extension) IsList() bool { return xd.Cardinality() == protoreflect.Repeated }
|
||||
func (xd *Extension) IsMap() bool { return false }
|
||||
func (xd *Extension) MapKey() protoreflect.FieldDescriptor { return nil }
|
||||
|
@ -495,6 +495,8 @@ func (xd *Extension) unmarshalOptions(b []byte) {
|
||||
switch num {
|
||||
case genid.FieldOptions_Packed_field_number:
|
||||
xd.L1.EditionFeatures.IsPacked = protowire.DecodeBool(v)
|
||||
case genid.FieldOptions_Lazy_field_number:
|
||||
xd.L1.IsLazy = protowire.DecodeBool(v)
|
||||
}
|
||||
case protowire.BytesType:
|
||||
v, m := protowire.ConsumeBytes(b)
|
||||
|
@ -504,6 +504,8 @@ func (fd *Field) unmarshalOptions(b []byte) {
|
||||
fd.L1.EditionFeatures.IsPacked = protowire.DecodeBool(v)
|
||||
case genid.FieldOptions_Weak_field_number:
|
||||
fd.L1.IsWeak = protowire.DecodeBool(v)
|
||||
case genid.FieldOptions_Lazy_field_number:
|
||||
fd.L1.IsLazy = protowire.DecodeBool(v)
|
||||
case FieldOptions_EnforceUTF8:
|
||||
fd.L1.EditionFeatures.IsUTF8Validated = protowire.DecodeBool(v)
|
||||
}
|
||||
|
@ -160,6 +160,7 @@ func (x placeholderExtension) HasPresence() bool
|
||||
func (x placeholderExtension) HasOptionalKeyword() bool { return false }
|
||||
func (x placeholderExtension) IsExtension() bool { return true }
|
||||
func (x placeholderExtension) IsWeak() bool { return false }
|
||||
func (x placeholderExtension) IsLazy() bool { return false }
|
||||
func (x placeholderExtension) IsPacked() bool { return false }
|
||||
func (x placeholderExtension) IsList() bool { return false }
|
||||
func (x placeholderExtension) IsMap() bool { return false }
|
||||
|
@ -150,6 +150,7 @@ func (r descsByName) initFieldsFromDescriptorProto(fds []*descriptorpb.FieldDesc
|
||||
opts = proto.Clone(opts).(*descriptorpb.FieldOptions)
|
||||
f.L1.Options = func() protoreflect.ProtoMessage { return opts }
|
||||
f.L1.IsWeak = opts.GetWeak()
|
||||
f.L1.IsLazy = opts.GetLazy()
|
||||
if opts.Packed != nil {
|
||||
f.L1.EditionFeatures.IsPacked = opts.GetPacked()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user