标量消息字段可以具有以下类型之一 - 该表显示.proto
文件中指定的类型,以及自动生成的类中的相应类型:
.proto Type | Notes | C++ Type | Java Type | Python Type[2] | Go Type |
---|---|---|---|---|---|
double | 固定8字节长度 | double | double | float | float64 |
float | 固定4字节长度 | float | float | float | float32 |
int32 | 可变长度编码。对负数编码低效,如果字段可能是负数,用sint32代替 | int32 | int | int | int32 |
int64 | 可变长度编码。对负数编码低效,如果字段可能是负数,用sint64代替 | int64 | long | int/long[3] | int64 |
uint32 | 可变长度编码,无符号整数 | uint32 | int[1] | int/long[3] | uint32 |
uint64 | 可变长度编码,无符号整数 | uint64 | long[1] | int/long[3] | uint64 |
sint32 | 可变长度编码。有符号整数。 These more efficiently encode negative numbers than regular int32s. | int32 | int | int | int32 |
sint64 | 可变长度编码。有符号整数。These more efficiently encode negative numbers than regular int64s. | int64 | long | int/long[3] | int64 |
fixed32 | 固定4字节长度,无符号整数。 More efficient than uint32 if values are often greater than 228. | uint32 | int[1] | int/long[3] | uint32 |
fixed64 | 固定8字节长度,无符号整数。 More efficient than uint64 if values are often greater than 256. | uint64 | long[1] | int/long[3] | uint64 |
sfixed32 | 固定4字节长度,有符号整数 | int32 | int | int | int32 |
sfixed64 | 固定8字节长度,有符号整数 | int64 | long | int/long[3] | int64 |
bool | bool | boolean | bool | bool | |
string | UTF-8 encoded or 7-bit ASCII text. | string | String | str/unicode[4] | string |
bytes | 包含任意字节序列 | string | ByteString | str | []byte |