本文章整理上传于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.youkuaiyun.com/eric520zenobia/article/details/53766571