当前位置: 首页 > news >正文

thrift linux java,Thrift, Protocol Buffers installation and Java code howto

I. Thrift installation and Java code

1. build and install thrift

install boost

cd /tools/jam

./build_dist.sh

# linux* will depends the platform

cp stage/bin.linux*/bjam

# build boost, use bjam will faster

cd

./configure –without-icu –prefix=/usr/local/boost

./bjam -toolset=gcc –build-type=release install –prefix=/usr/local/boost

# build thrift

./bootstrap.sh

./configure –with-boost=/usr/local

make

make install

2. Build Thrift java library

install apache ant if necessary

cd lib/java/

ant

get libthrift.jar

3. Create .thrift file and gen Java code

(See http://wiki.apache.org/thrift/Tutorial for more .thrift tutorial info)

tim.thrift

struct dns_record {

1: string key,

2: string value,

3: string type = 'A',

4: i32 ttl = 86400,

5: string first,

6: string last

}

service TestDns {

dns_record test(1:string q);

}

/bin/thrift –gen java tim.thrift

code will be generated in gen-java/*.java

4. Write java code

// new object

dns_record dr = new dns_record(key, value, type, ttl, first, last)

// serialize

TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());

TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());

byte[] bytes = serializer.serialize(dr);

II. Protocol Buffers install and Java code

1. Build and install Protocol buffers

./configure

make

make install

2. Build protobuf Java library

install maven if not necessary

cd protobuf/java

mvn test

mvn package

get jar from target/protobuf-java-x.x.x.jar

3. Create .proto file and gen Java code

tim.proto

package dns;

message DnsRecord {

required string key = 1;

required string value = 2;

required string first = 3;

required string last = 4;

optional string type = 5 [default = "A"];

optional int32  ttl = 6 [default = 86400];

}

message DnsResponse {

repeated DnsRecord records = 1;

}

bin/protoc –java_out . tim.proto

4. Write Java code

// protocol buffer need a builder to create object

Dns.DnsRecord.Builder b = Dns.DnsRecord.newBuilder();

b.setKey("key");

b.setValue("value...");

...

b.builder();

byte[] bytes = dr.toByteArray();

Dns.DnsRecord dr2 = Dns.DnsRecord.parseFrom(bytes);

III. Resources

相关文章:

  • linux里c语言实现http服务序,c/s模式Linux下用c语言实现发送http请求
  • linux下llt测试技巧,HLT与LLT测试简介
  • Linux系统安装matplotlib,linux – ImportError:没有安装了matplotlib的名为matplotlib的模块...
  • linux+qq+输入法下载官网,续:Linux下安装输入法和QQ软件
  • linux文件io缓冲区,linux下的文件IO缓冲区,及其相关操作
  • C语言坐标系判断范围,给定坐标点,判断是否在某区域范围内 地理围栏算法
  • c语言编程函数坐标式,vc++ 6.0 里面有没有坐标函数哦
  • linux计划任务date,Linux计划任务定时备份数据
  • 删除指定下标的字符c语言,C语言 删除字符串中指定下标
  • 大学c语言 81页答案,七上英语教与学答案78页到81页
  • C语言h文件可以定义变量吗,C语言h文件头中的变量初始化
  • 幻方c语言编程,C语言程序编程:输入奇数输出n阶幻方矩阵.docx
  • 中国石油大学c语言上机题目答案,中国石油大学C语言上机题答案(2013版)答案_最全最详细...
  • 知道计算机c语言期末考试题库,大学计算机基础期末考试试题题库及答案.doc
  • 小度c1语言控制电视,小度在家1c怎么连接电视机
  • [译]如何构建服务器端web组件,为何要构建?
  • 2017届校招提前批面试回顾
  • 2017前端实习生面试总结
  • 230. Kth Smallest Element in a BST
  • CSS进阶篇--用CSS开启硬件加速来提高网站性能
  • Electron入门介绍
  • Hibernate【inverse和cascade属性】知识要点
  • Quartz初级教程
  • rabbitmq延迟消息示例
  • Spring Security中异常上抛机制及对于转型处理的一些感悟
  • 仿天猫超市收藏抛物线动画工具库
  • 个人博客开发系列:评论功能之GitHub账号OAuth授权
  • 跨域
  • 山寨一个 Promise
  • 深度解析利用ES6进行Promise封装总结
  • 使用 Node.js 的 nodemailer 模块发送邮件(支持 QQ、163 等、支持附件)
  • 使用common-codec进行md5加密
  • 体验javascript之美-第五课 匿名函数自执行和闭包是一回事儿吗?
  • 为视图添加丝滑的水波纹
  • 直播平台建设千万不要忘记流媒体服务器的存在 ...
  • ​​​​​​​​​​​​​​汽车网络信息安全分析方法论
  • ​软考-高级-信息系统项目管理师教程 第四版【第23章-组织通用管理-思维导图】​
  • # Swust 12th acm 邀请赛# [ E ] 01 String [题解]
  • # 深度解析 Socket 与 WebSocket:原理、区别与应用
  • #14vue3生成表单并跳转到外部地址的方式
  • #define
  • (1)bark-ml
  • (Mirage系列之二)VMware Horizon Mirage的经典用户用例及真实案例分析
  • (二)丶RabbitMQ的六大核心
  • (学习日记)2024.01.19
  • *2 echo、printf、mkdir命令的应用
  • .[hudsonL@cock.li].mkp勒索加密数据库完美恢复---惜分飞
  • .bat批处理(五):遍历指定目录下资源文件并更新
  • .bat批处理(一):@echo off
  • .class文件转换.java_从一个class文件深入理解Java字节码结构
  • .NET Framework 4.6.2改进了WPF和安全性
  • .NET LINQ 通常分 Syntax Query 和Syntax Method
  • .Net+SQL Server企业应用性能优化笔记4——精确查找瓶颈
  • .net6Api后台+uniapp导出Excel
  • .net反编译的九款神器