doujie3888 2018-05-25 15:22
浏览 683
已采纳

protoc-gen-go的新版本删除了已知类型

There are two .proto files

1st file | name "a.proto"

syntax = "proto3";

package a;

message AMsg{
    fixed64 smth1 = 1;
    fixed64 smth2 = 2;
}

2nd file | name "b.proto"

syntax = "proto3";

package b;

import "a.proto";

message BMsg {
    a.AMsg msg1 = 1;
    a.AMsg msg2 = 2;
}

previous versions of protoc-gen-go generated the following code:

file "a.pb.go"

package b

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"    

. . .  

type AMsg struct {
    smth1 uint64 
    smth2 uint64 
}

. . . 

file "b.pb.go"

package b

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"   
import "a"

. . .  

type BMsg struct {
    msg1 *a.AMsg
    msg2 *a.AMsg
}

. . . 

and everything was alright,

but

one day a new version of protoc-gen-go had come

and file "b.pb.go" now looks like this:

package b

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"   

. . .  

type BMsg struct {
    msg1 *AMsg
    msg2 *AMsg
}

. . . 

you can notice that already known types are dropped here, but i can't find out the reason. (i. e. prefix "a." i missing)

this link https://developers.google.com/protocol-buffers/docs/reference/go-generated says nothing about the new approach

What should I do to make protoc-gen-go to generate "b.pb.go" without these drops?

  • 写回答

1条回答 默认 最新

  • doudou20145 2018-08-30 10:52
    关注

    go_package option solved this, you should explicitly specify the package in a.proto

    like this:

    syntax = "proto3";
    
    package a;
    option go_package= "some_path/A";
    
    message AMsg{
        fixed64 smth1 = 1;
        fixed64 smth2 = 2;
    }
    

    so you will get right generated types from a.proto in other proto files

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?