标签:span 反序 new 对象序列化 java 对象 code util []
通过Protostuff进行序列化和反序列号
/** * 把MessageBody对象序列化为byte[] {@link MessageBody} * * @param MessageBody * @return */ public static byte[] serializeMessageBody(MessageBody messageBody) { byte[] bytes = null; Schema<MessageBody> schema = RuntimeSchema.getSchema(MessageBody.class); LinkedBuffer buffer = LinkedBuffer.allocate(4096); try { bytes = ProtostuffIOUtil.toByteArray(messageBody, schema, buffer); } finally { buffer.clear(); } return bytes; } /** * 反序列化,把byte[]转成MessageBody对象 * * @param bytes * @return */ public static MessageBody deserializeMessageBody(byte[] bytes) { MessageBody messageBody = new MessageBody(); Schema<MessageBody> schema = RuntimeSchema.getSchema(MessageBody.class); ProtostuffIOUtil.mergeFrom(bytes, messageBody, schema); return messageBody; }
标签:span 反序 new 对象序列化 java 对象 code util []
原文地址:http://www.cnblogs.com/hm-zhang/p/6231840.html