Conversation
timostamm
commented
May 13, 2024
| const oneof = findOneof(proto, allOneofs); | ||
| const field = newField(proto, message, reg, oneof, mapEntries); | ||
| message.fields.push(field); | ||
| message.field[field.localName] = field; |
Member
Author
There was a problem hiding this comment.
We're eagerly populating the record - it's quite simple and cheap.
| export function getPackageComments(desc: DescFile): DescComments { | ||
| return findComments(desc.proto.sourceCodeInfo, [ | ||
| FieldNumber.FileDescriptorProto_Package, | ||
| FileDescriptorProtoDesc.field.package.number, |
Member
Author
There was a problem hiding this comment.
That's a nice practical example of where this feature can be useful. I imagine it will also be useful to construct FieldMasks.
Comment on lines
+37
to
+41
| field: DescField, | ||
| ): boolean { | ||
| const field = messageDesc.fields.find((f) => f.localName === fieldName); | ||
| if (field) { | ||
| return unsafeIsSet(message, field); | ||
| } | ||
| return false; | ||
| return ( | ||
| field.parent.typeName == message.$typeName && unsafeIsSet(message, field) | ||
| ); |
Member
Author
There was a problem hiding this comment.
Same as before, a foreign field is never set, and clearing a foreign field is a no-op.
srikrsna-buf
approved these changes
May 13, 2024
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In some situations, it's useful to be able to refer to a field by name.
DescMessageprovides all fields in the propertyfields: DescField[]- that's convenient to loop through all fields, but it's awkward to pick a field by name.This PR adds another property to
DescMessage:In generated code, the property is a type-safe record. You get autocomplete for field names, and a typo is a compile-time error:
This PR also changes the signatures of
isFieldSetandclearFieldto make use of this new feature. Instead of having to pass in the message descriptor, the message, and the field name, both functions only require two arguments now: The message, and the field: