go-protoparser parses the proto3 
<https://developers.google.com/protocol-buffers/docs/reference/proto3-spec>
 file.

- https://github.com/yoheimuta/go-protoparser
- You can use it if you know one Parse function.

----

A Protocol Buffer file versioned 3 which is an example of the official 
reference.

syntax = "proto3";
// An example of the official reference
// See 
https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#proto_file
package examplepb;
import public "other.proto";
option java_package = "com.example.foo";
enum EnumAllowingAlias {
   option allow_alias = true;
   UNKNOWN = 0;
   STARTED = 1;
   RUNNING = 2 [(custom_option) = "hello world"];
}
message outer {
   option (my_option).a = true;
   message inner {   // Level 2
       int64 ival = 1;
   }
   repeated inner inner_message = 2;
   EnumAllowingAlias enum_field =3;
   map<int32, string> my_map = 4;
}


The Parsed result is a Go typed struct. The below output is encoded to JSON 
for simplicity.

{
 "Syntax": {
   "ProtobufVersion": "proto3",
   "Comments": null
 },
 "ProtoBody": [
   {
     "Name": "examplepb",
     "Comments": [
       {
         "Raw": "// An example of the official reference"
       },
       {
         "Raw": "// See 
https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#proto_file";
       }
     ]
   },
   {
     "Modifier": 1,
     "Location": "\"other.proto\"",
     "Comments": null
   },
   {
     "OptionName": "java_package",
     "Constant": "\"com.example.foo\"",
     "Comments": null
   },
   {
     "EnumName": "EnumAllowingAlias",
     "EnumBody": [
       {
         "OptionName": "allow_alias",
         "Constant": "true",
         "Comments": null
       },
       {
         "Ident": "UNKNOWN",
         "Number": "0",
         "EnumValueOptions": null,
         "Comments": null
       },
       {
         "Ident": "STARTED",
         "Number": "1",
         "EnumValueOptions": null,
         "Comments": null
       },
       {
         "Ident": "RUNNING",
         "Number": "2",
         "EnumValueOptions": [
           {
             "OptionName": "(custom_option)",
             "Constant": "\"hello world\""
           }
         ],
         "Comments": null
       }
     ],
     "Comments": null
   },
   {
     "MessageName": "outer",
     "MessageBody": [
       {
         "OptionName": "(my_option).a",
         "Constant": "true",
         "Comments": null
       },
       {
         "MessageName": "inner",
         "MessageBody": [
           {
             "IsRepeated": false,
             "Type": "int64",
             "FieldName": "ival",
             "FieldNumber": "1",
             "FieldOptions": null,
             "Comments": [
               {
                 "Raw": "// Level 2"
               }
             ]
           }
         ],
         "Comments": null
       },
       {
         "IsRepeated": true,
         "Type": "inner",
         "FieldName": "inner_message",
         "FieldNumber": "2",
         "FieldOptions": null,
         "Comments": null
       },
       {
         "IsRepeated": false,
         "Type": "EnumAllowingAlias",
         "FieldName": "enum_field",
         "FieldNumber": "3",
         "FieldOptions": null,
         "Comments": null
       },
       {
         "KeyType": "int32",
         "Type": "string",
         "MapName": "my_map",
         "FieldNumber": "4",
         "FieldOptions": null,
         "Comments": null
       }
     ],
     "Comments": null
   }
 ]
}

MIT License. Contributions and feedbacks welcome.

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to