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 ...
随机推荐
- 分析java类的初始化契机
分析java类的静态成员变量初始化先于非静态成员变量 依上图中当class字节码文件被jvm虚拟机加载到内存中依次经过 连接 验证:对字节码进行验证 准备:给静态变量分配内存并赋予变量类型各自的默 ...
- iframe有哪些缺点?
iframe会阻塞主页面的Onload事件: iframe和主页面共享连接池,而浏览器对相同域的连接有限制,所以会影响页面的并行加载.使用iframe之前需要考虑这两个缺点.如果需要使用ifram ...
- 一,我的Android Studio 3.0.1 安装过程
安装成功于20171231的0:46分. 简要记录我的安装过程如下: 一,安装JDK1.8.X 二,安装ANDROID STUDIO.ZIP 三,运行AS,后按提示下载SDK,NDK,必要时设置一下J ...
- svn关键词BASE, HEAD, COMMITTED, PREV的深入理解
svn关键词BASE, HEAD, COMMITTED, PREV可以很方便用于日常操作中,但是很多人对他们的工作原理和方式不是太了解. 在这里我将使用用例,诠释他们的作用和意图. 先给出svn手册中 ...
- Django学习---自定义分页
自定义分页 简单例子: urls.py: from django.contrib import admin from django.urls import path from django.conf. ...
- Rhythmk 一步一步学 JAVA (12) Spring-1 之入门
(一)简单对象Spring XML配置说明 使用Spring (Spring 3.0) 实现最简单的类映射以及引用,属性赋值: 1.1.新建类UserModel: package com.sprin ...
- c#中如何获取本机用户名、MAC地址、IP地址、硬盘ID、CPU序列号、系统名称、物理内存
我们在利用C#开发桌面程序(Winform)程序的时候, 经常需要获取一些跟系统相关的信息, 以下这些代码获取能有些用处. c#中如何获取本机用户名.MAC地址.IP地址.硬盘ID.CPU序列号.系统 ...
- leetcode289
public class Solution { public void GameOfLife(int[][] board) { ) - ; ].GetLength() - ; var list = n ...
- Elasticsearch-2.4.3的单节点安装(多种方式图文详解)
前提: Elasticsearch-2.4.3的下载(图文详解) 1.新建es安装目录 [root@djt002 local]# mkdir elasticsearch [root@djt002 lo ...
- 利用Surprise包进行电影推荐
Surprise(Simple Python Recommendation System Engine)是一款推荐系统库,是scikit系列中的一个.简单易用,同时支持多种推荐算法(基础算法.协同过滤 ...