doqo89924 2019-03-29 10:42
浏览 1490
已采纳

将golang类型定义为protobuf的.proto文件中其他类型的切片

I want to define a golang type in .proto file. The type is a slice of other type which is defined in .proto file.

I have types as below.

type SomeType struct {
    // few fields
}

type SomeTypes []SomeType

I have SomeType is defined in .proto file as below.

message SomeType {
    //
}

Now I want to define type SomeTypes in .proto file. But I have not found any way to do that. The simplest solution for me is to change type SomeTypes as below:

type SomeTypes struct {
    Content []SomeType
}

Then I can define that in .proto file as

message SomeTypes {
      repeated SomeType Content = 1 [(gogoproto.nullable) = false];
}

But I want to know if there is any solution which does not involve changing the struct SomeTypes

I am using proto2.

  • 写回答

1条回答 默认 最新

  • duanli0119 2019-04-05 11:38
    关注

    Found that there is an issue created in protobuf project: https://github.com/gogo/protobuf/issues/433 so it is confirmed that there is no other way currently.

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

报告相同问题?

悬赏问题

  • ¥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,如何解決?
  • ¥15 c++头文件不能识别CDialog