-
Notifications
You must be signed in to change notification settings - Fork 420
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
Conversation
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extendeeTypeName extendeeName: String, | |
named extendeeName: String, |
return self.fileNameByExtensionDescriptor[ | ||
ExtensionDescriptor(extendeeTypeName: extendeeName, fieldNumber: number) | ||
] |
There was a problem hiding this comment.
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]
extension Sequence where Element == Google_Protobuf_FieldDescriptorProto { | ||
var names: [String] { | ||
self.map { $0.name } | ||
} | ||
} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
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. | ||
""" | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
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.
8e8b34b
to
e7f6987
Compare
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:
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.