dongtiaobeng7901 2017-10-25 19:11
浏览 228

Protobuf:如何获得方法的正确选项顺序?

I am writing protoc plugin in Go which should generate documentation for our GRPC services and currently struggle in attempt to know right order of options.

First, how the protobuf looks like

 syntax = "proto3";
 option go_package = "sample";

 package sample

 import "common/extensions.proto"

 message SimpleMessage {
     // Id represents the message identifier.
     string id = 1;
     int64 num = 2;
 }

 message Response {
    int32 code = 1;
 }

 enum ErrorCodes {
     RESERVED = 0;
     OK    = 200
     ERROR = 6000
     PANIC = 6001
 }

 service EchoService {
     rpc Echo (SimpleMessage) returns (Response) {
        // common.grpc_status is an extension defined somewhere
        // these are list of possible return statuses
         option (common.grpc_status) = {
             status: "OK"
             status: "ERROR"
             status: "PANIC" // Every status string will must be one of ErrorCodes items
         };

         option (common.middlewares) = {
             middleware: "csrf"
             middleware: "session"
         }
     }
 };

As you see, there're two options here. The problem is protoc doesn't bind position directly to tokens. It leaves this information in a special sections where it can be restored via using so called "paths". And these paths are rely on order, while options are hidden and can only be retrieved using proto.GetExtension function which doesn't report option index either. I need this token location information to report errors. Is there any way to get option index or something equivalent?

I am thinking about using standalone parser just to retrieve the right order, but this feels somewhat awkward. Hope there's a better way.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿