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

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

图片转代码服务由CSDN问答提供 功能建议

我想在 .proto 中定义 golang 类型 文件。 该类型是.proto文件中定义的其他类型的切片。

我具有以下类型。

  type SomeType结构 {
 //几个字段
} 
 
type SomeTypes [] SomeType 
   
 
 

我在.proto中定义了 SomeType 文件如下。

 消息SomeType {
 // 
} 
   
 
 

现在我要定义 在.proto文件中键入 SomeTypes 。 但是我还没有找到任何办法。 对我来说,最简单的解决方案是如下更改类型 SomeTypes

  type SomeTypes struct {
 Content [] SomeType 
} 
 <  / code>  
 
 

然后我可以在.proto文件中将其定义为

 消息SomeTypes {
重复SomeType内容= 1 [(  gogoproto.nullable)= false]; 
} 
   
 
 

但是我想知道是否存在不涉及更改struct SomeTypes < / code>

我正在使用 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.

    点赞 评论

相关推荐 更多相似问题