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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!