protobuf 之 com.dyuproject.protostuff java 使用

 

本文章整理上傳於2017年9月14日

1.maven依賴

 

<protostuff.v>1.1.2</protostuff.v>

 <dependency>
	<groupId>com.dyuproject.protostuff</groupId>
	<artifactId>protostuff-api</artifactId>
	<version>${protostuff.v}</version>
</dependency>
<dependency>
	<groupId>com.dyuproject.protostuff</groupId>
	<artifactId>protostuff-core</artifactId>
	<version>${protostuff.v}</version>
</dependency>
<dependency>
	<groupId>com.dyuproject.protostuff</groupId>
	<artifactId>protostuff-runtime</artifactId>
	<version>${protostuff.v}</version>
</dependency>

 

 

 

2.java代碼

 

//需要userSchema
RuntimeSchema<User> userSchema = RuntimeSchema.createFrom(User.class);
//User是一個pojo對象
User user =new User("小明","9歲");
//序列化
byte[] bt = ProtobufIOUtil.toByteArray(user, userSchema,LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE));
Syetem.out.print(bt);
//反序列化
User user2 = userSchema.newMessage();
ProtobufIOUtil.mergeFrom(userBytes, user2, userSchema);
Syetem.out.print(user2);

3結尾.

關於序列化技術對比和分析可以參看另一位博主的技術文章:

http://www.cnblogs.com/xiaoMzjm/p/4555209.html

https://blog.csdn.net/eric520zenobia/article/details/53766571

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章