Google Protobuf Primer (2) Language Guide
去年年初初次接触 Google Protobuf,如今已经有不少变化,从这篇开始,续一下 :)
1. Specifying Field Rules
You specify that message fields are one of the following:
-
required
: a well-formed message must have exactly one of this field.
-
optional
: a well-formed message can have zero or one of this field (but not more than one).
-
repeated
: this field can be repeated any number of times (including zero) in a well-formed message. The order of the repeated values will be preserved.
For historical reasons, repeated fields of basic numeric types aren't encoded as efficiently as they could be. New code should use the special option [packed=true] to get a more efficient encoding. For example:
repeated int32 samples = 4 [packed=true];
But when you use it as the following:
message Locations {
repeated Location location = 1 [packed=true];
}
compile it, then you will got a warning:
[packed = true] can only be specified for repeated primitive fields.
So pay attention to the type of fields you intend to specify.
2. Scalar Value Types
proto Type
Notes
C++ Type
Java Type
double |
|
double |
double |
float |
|
float |
float |
int32 |
variable-len, inefficient for negative num |
int32 |
int |
int64 |
variable-len, inefficient for negative num |
int64 |
long |
uint32 |
variable-len |
uint32 |
int |
uint64 |
variable-len |
uint64 |
long |
sint32 |
variable-len, signed num |
int32 |
int |
sint64 |
variable-len, signed num |
int64 |
long |
fixed32 |
always 4-byte, efficient > 228
|
int32 |
int |
fixed64 |
always 8-byte, efficient > 256
|
int64 |
long |
sfixed32 |
always 4-byte |
int32 |
int |
sfixed64 |
always 8-btye |
int64 |
long |
bool |
|
bool |
boolean |
string |
UTF-8 string, 7-bit ASCII string |
string |
String |
bytes |
any arbitrary sequence of bytes |
string |
ByteString |
概括下:
- 可正可负,范围小(228或256以内):
sint32
或sint64
- 可正可负,范围大(228或256以上):
sfixed32
或sfixed64
- 只会正的,范围小(228或256以内):
uint32
或uint64
- 只会正的,范围大(228或256以上):
fixed32
或fixed64
- 布尔:
bool
- 浮点:
float
或double
- utf8 string 或 7-bit ascii string:
string
- ByteString:
bytes
-
转载请注明来自柳大的CSDN博客:Blog.CSDN.net/Poechant,微博:weibo.com/lauginhom
-
分享到:
相关推荐
google protobuf language guide
google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf 最新源代码google protobuf ...
服务器端与客户端通信,使用google protobuf作为交互数据的序列化工具,其中客户端使用select机制实现I/O复用,服务端使用epoll机制,提高并发连接时的处理效率。软件环境:linux。文件dealpack.cc是服务端和客户端...
Google ProtoBuf 安装使用说明
windows下vs环境对protobuf的简单应用,所用vs版本2010,protobuf版本protobuf-2.5.0
google protobuf的简单实用方法,主要用于向他人介绍。 可以用于数据传输和单元测试中 google protobuf的简单实用方法,主要用于向他人介绍。 可以用于数据传输和单元测试中
google protobuf库文件,编译方法,及使用 google protobuf学习笔记一:windows下环境配置
google protobuf对协议内容进行了编码和压缩,对协议安全很有意义
google protobuf C教程,主要实现将google protobuf移植到32位单片机的教程。
google protobuf-2.4.1
使用google protobuf通过TCP传输文件
google protobuf-3.2.0 protoc3.2.0.exe
protocolbuffer(以下简称PB)是google 的一种数据交换的格式,它独立于语言,独立于平台 提供了多种语言的实现:java、c#、c++、go 和 python,是一种效率和兼容性都很优秀的二进制数据传输格式,可以用于诸如网络...
to-date version of the descriptor.proto file into the plugin jar under .p2\pool\plugins\com.google.eclipse.protobuf_2.3.2.201609161849.jar and restarted Eclipse which resolved this. -- @gfecher ...
google protobuf 2.6.0源文件可直接编译使用!!!!!!!!!!!!!!!!!!!!!
required string name = 2; optional string email = 3; } Then you compile it with protoc, the protocol buffer compiler, to produce code in C++, Java, or Python. Then, if you are using C++, you use ...
google protobuf英文文档,学习google protobuf必备一册
ProtocolBuffer是用于结构化数据串行化的灵活、高效、自动的方法,有如XML,不过它更小、更快、也更简单。你可以定义自己的数据结构,...protobuf-java-3.2.0.jar包 太难找了,只能是自己发布一个jar包 特此分享出来
protobuf-java-2.5.0.ar protobuf-2.5.0-win32 readme.txt(使用文档)