-
-
Notifications
You must be signed in to change notification settings - Fork 138
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 descriptor loader #87
Conversation
{ | ||
InputStream fin; | ||
fin = this.getClass().getClassLoader().getResourceAsStream(descriptorFilePath); | ||
if (fin == null) { |
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.
If the resource can not be read, why would accessing it as URL
work differently (and should it)? Maybe at least add a comment explaining what is the motivation here
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.
I was trying to make it dual purpose -- load the descriptor from resources directory as well as external URL. I will remove the resources. I guess the descriptors in the resources directory is only useful for unit tests.
NativeProtobufSchema nativeSchema = NativeProtobufSchema.construct(protoFileMap.get("main.proto")); | ||
|
||
ProtobufSchema schema = nativeSchema.forType("main1"); | ||
System.out.println(schema.toString()); |
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 should be removed.
Ok, I think this could be a good starting point. There are some things I'd probably change, such as making But one question first: what is intended usage pattern for |
Thanks for the comments. The reason why I exposed
The test case barely shows that the two .proto files (main.proto and other.proto) are merged. I will add tests that actually check the correctness of the output. Other items that you pointed out:
|
- rename DescriptorReader to DescriptorLoader - return ProtobufSchema instead of NativeProtobufSchema - find the main .proto file by message type. - remove "main .proto file" concept. - introduce FileDescriptorSet POJO
Unfortunately haven't had time to spend on this, but wanted to add a note to say it's still on my radar. |
try { | ||
in.close(); | ||
} | ||
catch (IOException e) { |
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.
Why catch? Shouldn't it just be propagated as-is?
Actually I think I can make some changes here from API perspective, but retain functionality. |
Ok so did refactoring, which is sizable by lines of code. But didn't much change functionality: mostly just changes access point, which is now via |
This is a preliminary work for the #78 "create ProtoSchema from descriptor file".
A "descriptor file" is a set of descriptors. A descriptor is a binary representation of the .proto file. Typically one (or more) of the descriptors is the main, and the others are dependencies.
This reader creates a
NativeProtobufSchema
object from the main descriptor. Dependencies are "copied" into the main descriptor before generating the object. I chose copying over implementing the import mechanism per #86 discussion. The import statement is a potential security risk, and it would certainly add the complexity.This descriptor reader should work for simple message types that do not have references to other nested message types. #73 needs to be fixed.
Note: descriptor.proto was copied from Google Protobuf. The
reserved
fields were commented out because ProtoParser could not parse. See #84.