/(ㄒ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的更多相关文章

  1. google protobuf安装与使用

    google protobuf是一个灵活的.高效的用于序列化数据的协议.相比较XML和JSON格式,protobuf更小.更快.更便捷.google protobuf是跨语言的,并且自带了一个编译器( ...

  2. VS2013编译google protobuf 出现问题error C3861: “min”:

    问题描述: 今天用vs2013编译protobuf 2.4.1 报错: 错误 3 error C3861: "max": 找不到标识符 f:\google\protobuf\pro ...

  3. google protobuf初体验

    最近在读别人代码的时候发现一个的东西,名字叫protobuf, 感觉挺好用的,写在这里,留个记录.那么什么是protobuf 呢?假如您在网上搜索,应该会得到类似这样的文字介绍: Google Pro ...

  4. Google protobuf proto文件编写规则

    转载自: http://blog.csdn.net/yi_ya/article/details/40404231 1. 简单介绍 protobuf文件:就是定义你要的消息(类似java中的类)和消息中 ...

  5. window下编译并使用google protobuf

    参考网址: http://my.oschina.net/chenleijava/blog/261263 http://www.ibm.com/developerworks/cn/linux/l-cn- ...

  6. GOOGLE PROTOBUF开发者指南

    原文地址:http://www.cppblog.com/liquidx/archive/2009/06/23/88366.html 译者: gashero 目录 1   概览 1.1   什么是pro ...

  7. google protobuf ios开发使用

    简介: protobuf 即 google protocol buffer 是一种数据封装格式协议: 比如其他经常用的xml,json等格式:protobuf的优势是效率高,同样的一份数据使用prot ...

  8. Google protobuf

    个人理解: 定义.proto文件就是指明消息里包含的成员和类型,protoc会compile成相应的java文件包含interface和implementation class,然后在构建messag ...

  9. google protobuf 简单实例

    1.定义proto文件: User.proto package netty; option java_package="myprotobuf"; option java_outer ...

  10. google protobuf使用

    下载的是github上的:https://github.com/google/protobuf If you get the source from github, you need to gener ...

随机推荐

  1. Druid.io系列(二):基本概念与架构

    原文链接:  https://blog.csdn.net/njpjsoftdev/article/details/52955788 在介绍Druid架构之前,我们先结合有关OLAP的基本原理来理解Dr ...

  2. Oracle回收站使用全攻略

    摘要:回收站(Recycle Bin)从原理上来说就是一个数据字典表,放置用户删除(drop)掉的数据库对象信息.用户进行删除操作的对象并没有被数据库删除,仍然会占用空间.除非是由于用户手工进行Pur ...

  3. bbbbb

  4. 给深度学习入门者的Python快速教程

    给深度学习入门者的Python快速教程 基础篇 numpy和Matplotlib篇 本篇部分代码的下载地址: https://github.com/frombeijingwithlove/dlcv_f ...

  5. Web(Easy UI)

    HTML菜鸟教程 http://www.runoob.com/html/html-tables.html EasyUI combobox下拉多选框的实现 https://www.cnblogs.com ...

  6. MongoDB + Spark: 完整的大数据解决方案

    Spark介绍 按照官方的定义,Spark 是一个通用,快速,适用于大规模数据的处理引擎. 通用性:我们可以使用Spark SQL来执行常规分析, Spark Streaming 来流数据处理, 以及 ...

  7. leetcode334

    public class Solution { public bool IncreasingTriplet(int[] nums) { var len = nums.Length; ) { retur ...

  8. 由于安装Android设备驱动异常,ADB无法识别安卓设备的解决方案

    体验更优排版请移步原文:http://blog.kwin.wang/programming/android-driver-exception-solution.html 最近换了台新电脑,在Andro ...

  9. delphi IOS BLE 代理

    代理方法 centralManagerDidUpdateState: peripheralManagerDidUpdateState:代理方法. centralManager:willRestoreS ...

  10. C++提高编译与链接速度的资料

    1,https://blog.csdn.net/lihao21/article/details/47610309 2,https://www.zhihu.com/question/37330979 3 ...