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 无源定位系统的时差估计误差标准差
  • ¥15 请问这个代码哪里有问题啊
  • ¥20 python--version在命令端输入结果Python is not defined怎么办?还有pip不是exe格式是不是没安装成功?
  • ¥15 通过GaussianView进行结构微调消除虚频
  • ¥15 调用transformers库
  • ¥15 由于导出的数据名字中带有/,导致Matlab打不开,怎么办?
  • ¥15 新硬盘安装的程序总是崩溃,提示遇到错误
  • ¥15 openpcdet自制数据集评估bev精度和3d精度相同
  • ¥15 excel 上下按钮 显示行
  • ¥20 云卓h12pro 数传问题