hadoop yarn中新的系列化protocol buffers
1.安装protoc,附件里是win,llinux的文件,win配置下环境变量,或是linux下configure make make install
2.写protoc文件person.proto
package tutorial; option java_package="";//包名 option java_outer_classname="PersonProtos";//类名 message Person{ required string name = 1; //required为必填,optional为可为空 required int32 id =2; required string email = 3; message PhoneNumber{ required string number = 1; optional int32 type = 2; } repeated PhoneNumber phone = 4; }
2.protoc命令生成类到当前目录
protoc -java_out=. person.proto
3.测试类
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import com.zb.demo.protocalBuffers.PersonProtos.Person; /** * proto buffer实例 * @author dirk.zhang * */ public class ProtocalBufferExample { public static void main(String[] args) { Person person1 = Person.newBuilder() .setName("dirk.zhang") .setEmail("kongzhiguiji@aliyun.com") .setId(41) .addPhone(Person.PhoneNumber.newBuilder().setNumber("13522616858") .setType(0)) .addPhone(Person.PhoneNumber.newBuilder().setNumber("110").setType(1)).build(); try { FileOutputStream output = new FileOutputStream(new File("d:\\delete\\protobufExample.txt")); person1.writeTo(output); output.close(); } catch (Exception e) { System.out.println("write Error!"); } try { FileInputStream input = new FileInputStream(new File("d:\\delete\\protobufExample.txt")); Person person2 = Person.parseFrom(input); System.out.println("person2:"+person2); } catch (Exception e) { System.out.println("read Error"); } } }
相关推荐
Google Protocol Buffers 在 c# 中的应用
Protocol Buffers 2.4.1 jar
Protocol Buffers What is it? Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and...
google protocol buffers 官网中文教程
中文翻译Google Protocol Buffers中文教程中文翻译Google Protocol Buffers中文教程中文翻译Google Protocol Buffers中文教程中文翻译Google Protocol Buffers中文教程
本源码为android编程人员使用protocol buffer提供了一个基本的介绍,通过一个简单的例程进行介绍。通过本文,你可以了解到如下信息: 1、使用Java protocol buffer API进行读写操作.
google Protocol Buffers
NULL 博文链接:https://lfl2011.iteye.com/blog/2136272
Google.ProtocolBuffers.dll类库
Google.ProtocolBuffers动态库反编译生成的源代码,用于学习。
Protocol Buffers Java开发包(protobuf-java-2.3.0.jar)
Protocol Buffers v3.0.0-alpha-1(Java) release 版本和源代码
Protocol Buffers - 谷歌的数据交换格式
This project contains the implementation of Protocol Buffers for Delphi. From the project was implemented limited functionality necessary for a specific project. At that time, I do not see any sense ...
在vs2015下编译生成的,最新版本的google的protocol buffers数据交互协议库,可以用于诸如网络传输、配置文件、数据存储等诸多领域。源码里包含了x86和x64编译的库以及一个x86下的可编译运行的测试Demo。
ProtocolBuffers 英文版PDF 不懂别下
Google Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,或者说序列化。它很适合做数据存储或 RPC 数据交换格式。可用于通讯协议、数据存储等领域的语言无关、平台无关、可扩展的...
ProtocolBuffers在即时通讯系统中的应用研究_田源.pdf
是mac ios的协议开发包,基于谷歌的protocol buffer技术, 能够实现多个平台的协议互通。容易使用。