LoginSignup
3
1

More than 3 years have passed since last update.

Protocol BuffersでGoのSlice・Mapを生成させる方法

Posted at

概要

Protocol Buffersで、Goにコンパイル後にSlice・Mapを生成させるために、protocol definitionにどのように定義すれば良いかの解説となります。

slice

repeatedを使う

message Result {
  repeated string message = 1;
}

これをコンパイルすると、

type Result struct {
        Messages  []string  
}

こうなります。

map

map<string, Bar> を使う


message Company {
  map<int32, string> members = 1;
}

これをコンパイルすると、

type Company struct {
        Members map[int32]string
}

こうなります。

参考

Go Generated Code - Protocol Buffers

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1