Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Parsing proto files #2204

Answered by oldergod
snssays asked this question in Q&A
Feb 17, 2022 · 1 comments · 2 replies
Discussion options

Hello, I am trying to parse a existing proto file in my local. And add some new code for eg:

syntax = "proto3";
package xx.stations.proto;
import "xx/stations/proto/wrappers.proto";
option java_multiple_files = true;
option java_package = "com.xx.stations.grpc.service";
option java_outer_classname = "StationsInternalApiV1Proto";
option objc_class_prefix = "STATIONS";
service StationsInternalApiV1 {
 
 rpc addStationToCollection (ListenerReq) returns (SuccessResponse) {}

to be changed as

syntax = "proto3";
package xx.stations.proto;
import "xx/stations/proto/wrappers.proto";
option java_multiple_files = true;
option java_package = "com.xx.stations.grpc.service";
option java_outer_classname = "StationsInternalApiV1Proto";
option objc_class_prefix = "STATIONS";
service StationsInternalApiV1 {
 
 rpc addStationToCollection (ListenerReq) returns (SuccessResponse) {
 option (google.api.http) = {
 post: "/addStationToCollection"
 body: "*"
 };
 }
 

I need to add this change all the method calls within the proto file. However instead of doing it manually. I would like to introduce code generation. I was wondering if I can use wire-schema in order to read the proto file and make changes to it through of any of the library classes. Please let me know.

You must be logged in to vote

That should be simple yes.
You don't even have to build the Schema, you could manipulate the parsed file directly.
Parse it with ProtoParser, you mutate the types you want, you could be iterating all ProtoFileElement#services, add the option you need or whatever change you wanna do, and reprint the protos with ProtoFileElement.toSchema().

Replies: 1 comment 2 replies

Comment options

That should be simple yes.
You don't even have to build the Schema, you could manipulate the parsed file directly.
Parse it with ProtoParser, you mutate the types you want, you could be iterating all ProtoFileElement#services, add the option you need or whatever change you wanna do, and reprint the protos with ProtoFileElement.toSchema().

You must be logged in to vote
2 replies
Comment options

Thank you, I was just able to find it. What's the parameter "data" represent. I understand location takes in the location of the protofile. What is data about?

Comment options

data is the content of the file.
You can otherwise try to use SchemaLoader. Look at the code or where it's used and you should be able to go.

Answer selected by snssays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /