Skip to content

Commit

Permalink
add comment per review suggestion; add another in the same vein, for …
Browse files Browse the repository at this point in the history
…clarity
  • Loading branch information
jhump committed Apr 8, 2024
1 parent 897e7c5 commit 2e63fc4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions linker/descriptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,8 @@ func (f *fldDescriptor) Cardinality() protoreflect.Cardinality {
return protoreflect.Required
case descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL:
if f.Syntax() == protoreflect.Editions {
// Editions does not use label to indicate required. It instead
// uses a feature, and label is always optional.
fieldPresence := descriptorpb.FeatureSet_FieldPresence(resolveFeature(f, fieldPresenceField).Enum())
if fieldPresence == descriptorpb.FeatureSet_LEGACY_REQUIRED {
return protoreflect.Required
Expand All @@ -1061,6 +1063,8 @@ func (f *fldDescriptor) Cardinality() protoreflect.Cardinality {

func (f *fldDescriptor) Kind() protoreflect.Kind {
if f.proto.GetType() == descriptorpb.FieldDescriptorProto_TYPE_MESSAGE && f.Syntax() == protoreflect.Editions {
// In editions, "group encoding" (aka "delimited encoding") is toggled
// via a feature. So we report group kind when that feature is enabled.
messageEncoding := resolveFeature(f, messageEncodingField)
if descriptorpb.FeatureSet_MessageEncoding(messageEncoding.Enum()) == descriptorpb.FeatureSet_DELIMITED {
return protoreflect.GroupKind
Expand Down

0 comments on commit 2e63fc4

Please sign in to comment.