Skip to content

Instantly share code, notes, and snippets.

@islishude
Last active September 3, 2019 11:10
Show Gist options
  • Save islishude/5a35e5de689d071eaa8b2dea2066511b to your computer and use it in GitHub Desktop.
Save islishude/5a35e5de689d071eaa8b2dea2066511b to your computer and use it in GitHub Desktop.
protobuf golang编码

protobuf data type

type go note
double float64
float float32
int32 int32 变长编码
int64 int64 变长编码
uint32 uint32 变长编码
uint64 uint64 变长编码
sint32 int32 有符号变长编码,相较 int32 对负数编码效率较高
sint64 int64 有符号变长编码,相较 int64 对负数编码效率较高
fixed32 uint32 总是 4 字节,对于值大于 2^28 的编码效率高于 uint32
fixed64 uint64 总是 8 字节,对于值大于 2^56 的编码效率高于 uint64.
sfixed32 int32 总是 4 字节
sfixed64 int64 总是 8 字节
bool bool
string string 必须始终包含 UTF-8 编码或 7 位 ASCII 的字符串,长度不能超过 2^32
bytes []byte 可以包含不超过 2^32 的任意字节序列。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment