package com.sdyc.ndmp.protobuf.serializer; import com.esotericsoftware.kryo.*; import com.esotericsoftware.kryo.io.Input; import com.esotericsoftware.kryo.io.Output; import com.google.protobuf.GeneratedMessage; /** *
 *
 * Created by IntelliJ IDEA.
 * User: zhenqin
 * Date: 14/12/10
 * Time: 09:55
 * To change this template use File | Settings | File Templates.
 *
 * 
* * @author zhenqin */ public class ProtobufKryoSerializer extends com.esotericsoftware.kryo.Serializer { protected final ProtobufSerializer protobufSerializer; public ProtobufKryoSerializer() { protobufSerializer = new ProtobufSerializer(); } @Override public void write(Kryo kryo, Output output, GeneratedMessage object) { byte[] bytes = protobufSerializer.serialize(object); output.writeInt(bytes.length, false); output.write(bytes); } @Override public GeneratedMessage read(Kryo kryo, Input input, Class type) { int i = input.readInt(false); byte[] bytes = new byte[i]; input.read(bytes); return protobufSerializer.deserialize(bytes); } }