Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FieldLiteral proto message #2752

Merged
merged 23 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions private/pkg/protosource/option_extension_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,9 @@ func isDescendantPath(descendant, ancestor []int32) bool {
return true
}

func (o *optionExtensionDescriptor) PresentFields() map[protoreflect.FieldDescriptor]protoreflect.Value {
func (o *optionExtensionDescriptor) Range(fn func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
// Note: This does not bother to handle unrecognized fields.
// Should not be a problem since descriptors models in the buf CLI codebase should have them
// all correctly parsed and known.
msg := o.message.ProtoReflect()
fields := map[protoreflect.FieldDescriptor]protoreflect.Value{}
msg.Range(func(fieldDescriptor protoreflect.FieldDescriptor, value protoreflect.Value) bool {
fields[fieldDescriptor] = value
return true
})
return fields
o.message.ProtoReflect().Range(fn)
}
7 changes: 3 additions & 4 deletions private/pkg/protosource/protosource.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ type OptionExtensionDescriptor interface {
// have a set value on this descriptor.
PresentExtensionNumbers() []int32

// PresentFields returns a map of field descriptor to value for all
// option fields present. This includes both normal option fields
// and extension fields (aka custom options).
PresentFields() map[protoreflect.FieldDescriptor]protoreflect.Value
// Range implements the same interface as protoreflect.Message. This takes
// in a callback that iterates over a protoreflect message field descriptors and values.
gilwong00 marked this conversation as resolved.
Show resolved Hide resolved
Range(fn func(protoreflect.FieldDescriptor, protoreflect.Value) bool)
gilwong00 marked this conversation as resolved.
Show resolved Hide resolved
}

// Location defines source code info location information.
Expand Down
Loading