google/protobuf hello world
/(ㄒoㄒ)/~~ 官网被墙
1. github > Search > protobuf or protocol buffers
2.https://github.com/google/protobuf
3. releases
4. protoc-3.0.0-alpha-2-win32.zip
readme.txt
Protocol Buffers - Google's data interchange format
Copyright Google Inc.
https://developers.google.com/protocol-buffers/ This package contains a precompiled Win32 binary version of the protocol buffer
compiler (protoc). This binary is intended for Windows users who want to
use Protocol Buffers in Java or Python but do not want to compile protoc
themselves. To install, simply place this binary somewhere in your PATH. This binary was built using MinGW, but the output is the same regardless of
the C++ compiler used. You will still need to download the source code package in order to obtain the
Java or Python runtime libraries. Get it from:
https://github.com/google/protobuf/releases/
将 protoc.exe 放至 C:\WINDOWS\system32
cmd
protoc --version
libprotoc 3.0.
protoc -h
Usage: protoc [OPTION] PROTO_FILES
Parse PROTO_FILES and generate output based on the options given:
-IPATH, --proto_path=PATH Specify the directory in which to search for
imports. May be specified multiple times;
directories will be searched in order. If not
given, the current working directory is used.
--version Show version info and exit.
-h, --help Show this text and exit.
--encode=MESSAGE_TYPE Read a text-format message of the given type
from standard input and write it in binary
to standard output. The message type must
be defined in PROTO_FILES or their imports.
--decode=MESSAGE_TYPE Read a binary message of the given type from
standard input and write it in text format
to standard output. The message type must
be defined in PROTO_FILES or their imports.
--decode_raw Read an arbitrary protocol message from
standard input and write the raw tag/value
pairs in text format to standard output. No
PROTO_FILES should be given when using this
flag.
-oFILE, Writes a FileDescriptorSet (a protocol buffer,
--descriptor_set_out=FILE defined in descriptor.proto) containing all of
the input files to FILE.
--include_imports When using --descriptor_set_out, also include
all dependencies of the input files in the
set, so that the set is self-contained.
--include_source_info When using --descriptor_set_out, do not strip
SourceCodeInfo from the FileDescriptorProto.
This results in vastly larger descriptors that
include information about the original
location of each decl in the source file as
well as surrounding comments.
--error_format=FORMAT Set the format in which to print errors.
FORMAT may be 'gcc' (the default) or 'msvs'
(Microsoft Visual Studio format).
--print_free_field_numbers Print the free field numbers of the messages
defined in the given proto files. Groups share
the same field number space with the parent
message. Extension ranges are counted as
occupied fields numbers.
--plugin=EXECUTABLE Specifies a plugin executable to use.
Normally, protoc searches the PATH for
plugins, but you may specify additional
executables not in the path using this flag.
Additionally, EXECUTABLE may be of the form
NAME=PATH, in which case the given plugin name
is mapped to the given executable even if
the executable's own name differs.
--cpp_out=OUT_DIR Generate C++ header and source.
--java_out=OUT_DIR Generate Java source file.
--javanano_out=OUT_DIR Generate Java Nano source file.
--python_out=OUT_DIR Generate Python source file.
--ruby_out=OUT_DIR Generate Ruby source file.
protoc --java_out=. addressbook.proto
[libprotobuf WARNING google/protobuf/compiler/parser.cc:] No syntax specified for the proto file. Please use 'syntax
= "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
遭遇以上问题时,请确保proto file 中 已指定syntax ,然后重试。
具体查看 https://github.com/google/protobuf/blob/master/CHANGES.txt
A new notion "syntax" is introduced to specify whether a .proto file
uses proto2 or proto3: // foo.proto
syntax = "proto3";
message Bar {...}
5. 消息模板文件位置
clone https://github.com/google/protobuf.git
文件位于 \protobuf\examples
6. maven 依赖
<repositories>
<repository>
<id>oschina</id>
<url>http://maven.oschina.net/content/groups/public/</url>
</repository>
</repositories> <dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.0.0-alpha-2</version>
</dependency>
</dependencies>
7. 完整示例
help tree
tree /F
E:.
└─hello-protocol
│ ADDRESS_BOOK_FILE
│ pom.xml
│
└─src
└─main
└─java
└─cn
└─zxg
AddPerson.java
AddressBookProtos.java
ListPeople.java
执行AddPerson 参数为 ADDRESS_BOOK_FILE 结果:
ADDRESS_BOOK_FILE: File not found. Creating a new file.
Enter person ID:
Enter name: James
Enter email address (blank for none): @.com
Enter a phone number (or leave blank to finish):
Is this a mobile, home, or work phone? work
Enter a phone number (or leave blank to finish):
执行ListPerson 参数为 ADDRESS_BOOK_FILE 结果:
Person ID:
Name: James
E-mail address: @.com
Work phone #:
google/protobuf hello world的更多相关文章
- google protobuf安装与使用
google protobuf是一个灵活的.高效的用于序列化数据的协议.相比较XML和JSON格式,protobuf更小.更快.更便捷.google protobuf是跨语言的,并且自带了一个编译器( ...
- VS2013编译google protobuf 出现问题error C3861: “min”:
问题描述: 今天用vs2013编译protobuf 2.4.1 报错: 错误 3 error C3861: "max": 找不到标识符 f:\google\protobuf\pro ...
- google protobuf初体验
最近在读别人代码的时候发现一个的东西,名字叫protobuf, 感觉挺好用的,写在这里,留个记录.那么什么是protobuf 呢?假如您在网上搜索,应该会得到类似这样的文字介绍: Google Pro ...
- Google protobuf proto文件编写规则
转载自: http://blog.csdn.net/yi_ya/article/details/40404231 1. 简单介绍 protobuf文件:就是定义你要的消息(类似java中的类)和消息中 ...
- window下编译并使用google protobuf
参考网址: http://my.oschina.net/chenleijava/blog/261263 http://www.ibm.com/developerworks/cn/linux/l-cn- ...
- GOOGLE PROTOBUF开发者指南
原文地址:http://www.cppblog.com/liquidx/archive/2009/06/23/88366.html 译者: gashero 目录 1 概览 1.1 什么是pro ...
- google protobuf ios开发使用
简介: protobuf 即 google protocol buffer 是一种数据封装格式协议: 比如其他经常用的xml,json等格式:protobuf的优势是效率高,同样的一份数据使用prot ...
- Google protobuf
个人理解: 定义.proto文件就是指明消息里包含的成员和类型,protoc会compile成相应的java文件包含interface和implementation class,然后在构建messag ...
- google protobuf 简单实例
1.定义proto文件: User.proto package netty; option java_package="myprotobuf"; option java_outer ...
- google protobuf使用
下载的是github上的:https://github.com/google/protobuf If you get the source from github, you need to gener ...
随机推荐
- 什么是 MVC ?
本篇博客打算简单介绍一下MVC是什么,为接下来MVC的学习做一下铺垫. MVC是一种架构设计模式,是一种设计理念.是为了达到分层设计的目的,从而使代码解耦,便于维护和代码的复用.MVC是3个单词的缩写 ...
- java爬虫简单实例
爬虫的实质就是打开网页源代码进行匹配查找,然后获取查找到的结果./** 获取* 将正则规则进行对象的封装. * Pattern p = Pattern.compile("a*b") ...
- Python代码审计中一些需要重点关注的项
SQL注入: 如果是常规没有进行预编译,或者直接使用原生的进行拼凑,那么在view的时候就需要多去观察了 [PythonSQL预编译]https://www.cnblogs.com/sevck/p/6 ...
- 使用国内源部署ceph
由于网络方面的原因,Ceph的部署经常受到干扰,通常为了加速部署,基本上大家都是将Ceph的源同步到本地进行安装.根据Ceph中国社区的统计,当前已经有国内的网站定期将Ceph安装源同步,极大的方便了 ...
- [Python] Argparse module
he recommended command-line parsing module in the Python standard library 1. Basic import argparse p ...
- JS 对输入框文本正在输入中校验
// keyup getInput.keyup(function(){ var a = parseInt(getPrice); var b = parseInt(getInput.val()); // ...
- 跟着太白老师学python 10day 函数的动态参数 *args, **kwargs, 形参的位置顺序
1. *args 接收实参的位置参数, **kwargs接收实参的关键字参数 def func(*args, **kwargs): print(args, kwargs) func(1, 2, 3, ...
- 4.2 最邻近规则分类(K-Nearest Neighbor)KNN算法应用
1 数据集介绍: 虹膜 150个实例 萼片长度,萼片宽度,花瓣长度,花瓣宽度 (sepal length, sepal width, petal length and petal wi ...
- iOS学习之UIDatePicker控件使用
iOS上的选择时间日期的控件是这样的,左边是时间和日期混合,右边是单纯的日期模式. , 您可以选择自己需要的模式,Time, Date,Date and Time , Count Down Ti ...
- 关于PHP如何用实现防止用户在浏览器上使用后退功能重复提交输入
$(function(){ if(window.history && window.history.pushState){ $(window).on('popstate',functi ...