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

Implemented file-containing-extension request for Reflection Service #1677

Merged
merged 2 commits into from
Oct 19, 2023

Conversation

stefanadranca
Copy link
Collaborator

@stefanadranca stefanadranca commented Oct 18, 2023

Motivation:

The file-containing-extension request enables users to get the file descriptor protos of the proto file containing the extension they are looking for and its transitive dependencies.

Modifications:

  • Created a new struct (ExtensionDescriptor) to represent the type that is extended and the field number of each extension that exists inside the protos passed to the Reflection Service.
  • Added a <ExtensionDescriptor, FileName> dictionary inside the ReflectionServiceData registry to store the extensions, avoid duplicates and retrieve nicely the file name of the proto that contains the requested extension. The file name is then used to get the serialized file descriptor protos of the proto containing the extension and its transitive dependencies.
  • Added integration and unit tests.

Result:

The Reflection Service can now be used to get the serialized file descriptor protos of the proto containing the provided extension and its transitive dependencies.

@stefanadranca stefanadranca changed the title Implemented file-containing-extension request for the Reflection Serv… Implemented file-containing-extension request for Reflection Service Oct 18, 2023
@@ -119,6 +149,15 @@ internal struct ReflectionServiceData: Sendable {
internal func nameOfFileContainingSymbol(named symbolName: String) -> String? {
return self.fileNameBySymbol[symbolName]
}

internal func nameOfFileContainingExtension(
extendeeTypeName extendeeName: String,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
extendeeTypeName extendeeName: String,
named extendeeName: String,

Comment on lines 157 to 159
return self.fileNameByExtensionDescriptor[
ExtensionDescriptor(extendeeTypeName: extendeeName, fieldNumber: number)
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty weird to format it this way... better to make the key then lookup:

let key = ExtensionDescriptor(extendeeTypeName: extendeeName, fieldNumber: number)
return self.fileNameByExtensionDescriptor[key]

Comment on lines 133 to 137
extension Sequence where Element == Google_Protobuf_FieldDescriptorProto {
var names: [String] {
self.map { $0.name }
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extension is so simple that I don't think it's worth defining, especially as it's only used in one place.

extendeeTypeName: "InvalidType",
fieldNumber: 2
)
XCTAssertEqual(registryFileName, nil)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use XCTAssertNil(registryFileName) (and elsewhere)

Comment on lines 209 to 231
for fileDescriptorProto in receivedData {
if fileDescriptorProto == fileToFind {
XCTAssert(
fileDescriptorProto.extension.names.contains("extensionInputMessage1"),
"""
The response doesn't contain the serialized file descriptor proto \
containing the \"extensionInputMessage1\" extension.
"""
)
} else {
XCTAssert(
dependentProtos.contains(fileDescriptorProto),
"""
The \(fileDescriptorProto.name) is not a dependency of the \
proto file containing the \"extensionInputMessage1\" symbol.
"""
)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a good test because receivedData could be an empty array which is clearly not right! If it's non-empty it's possible that it contains only fileToFind or only dependentProtos. In all cases the test would pass but shouldn't.

…ice.

Motivation:

The file-containing-extension request enables users to get the file descriptor protos of
the proto file containing the extension they are looking for and its transitive dependencies.

Modifications:

- Created a new struct (ExtensionDescriptor) to represent the type that is extended and the field number of each extension that
exists inside the protos passed to the Reflection Service.
- Added a <ExtensionDescriptor, FileName> dictionary inside the ReflectionServiceData registry to store the extensions, avoid
duplicates and retrieve nicely the file name of the proto that contains the requested extension. The file name is then used to
get the serialized file descriptor protos of the proto containing the extension and its transitive dependencies.
- Added integration and unit tests.

Result:

The Reflection Service can now be used to get the serialized file descriptor protos of the proto containing the provided
extension and its transitive dependencies.
@glbrntt glbrntt added semver/minor Adds new public API. semver/patch No public API change. and removed semver/minor Adds new public API. labels Oct 19, 2023
@glbrntt glbrntt merged commit cd104a0 into grpc:main Oct 19, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants