/(ㄒ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. 【UVa】439 Knight Moves(dfs)

    题目 题目     分析 没有估价函数的IDA......     代码 #include <cstdio> #include <cstring> #include <a ...

  2. VRF实例说明

    Virtual Routing Forwarding       VPN路由转发表,也称VPN-instance(VPN实例),是PE为直接相连的site建立并维护的一个专门实体,每个site在PE上 ...

  3. Tkinter Colors(颜色)

          Tkinter Colors: Tkinter的代表与字符串的颜色.一般有两种方式来指定Tkinter的颜色 Tkinter的代表与字符串的颜色.一般有两种方式来指定Tkinter的颜色: ...

  4. 13_java之final|static|包|匿名对象|代码块|内部类

    01final关键字概念 * A: 概述 继承的出现提高了代码的复用性,并方便开发.但随之也有问题,有些类在描述完之后,不想被继承, 或者有些类中的部分方法功能是固定的,不想让子类重写.可是当子类继承 ...

  5. processlist中最哪些状态要引起关注

    一般而言,我们在processlist结果中如果经常能看到某些SQL的话,至少可以说明这些SQL的频率很高,通常需要对这些SQL进行进一步优化. 今天我们要说的是,在processlist中,看到哪些 ...

  6. Delegate(代理)异常:该委托必须有一个目标

    转自 Delegate(代理)异常:该委托必须有一个目标 在代理调用BeginInvoke(new AsyncCallback(callBack), null);时,会抛这个异常的原因是该代理变量代理 ...

  7. leetcode503

    public class Solution { public int[] NextGreaterElements(int[] nums) { int n = nums.Length; int[] ne ...

  8. 调试正常,签名打包提示 "x应用未安装。"

    今天在工作的时候遇到一个奇葩的问题,开发一个新项目,然后在AS中调试运行都是一切正常.打包签名后,缺无法安装,提示"x应用未安装."如图所示. 网上找了好多方法,比如,签名的时候要 ...

  9. Dubbo-Admin管理平台和Zookeeper注册中心的搭建(只支持jdk7)

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubb ...

  10. Mybatis 针对ORACLE和MYSQL的批量插入与多参数批量删除

    今天利用Mybatis的<for each>标签做oracle的批量插入数据时,发现和MySQL数据库有区别.在此记录下,以防之后再踩坑. 一.批量插入: 1.controller: /* ...