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

将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.

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

报告相同问题?