Permalink
Browse files

Merge pull request #1 from johnynek/master

Minor TBase updates
  • Loading branch information...
2 parents 9e902d4 + c2a5e31 commit 066ee72abc534ea2a572e1865a213ed666d85d2c @sritchie sritchie committed Feb 10, 2012
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/jvm/meatlocker/TBaseSerializer.java
@@ -1,6 +1,7 @@
package meatlocker;
import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.serialize.IntSerializer;
import org.apache.thrift.TBase;
import org.apache.thrift.TDeserializer;
import org.apache.thrift.TException;
@@ -16,16 +17,20 @@
@Override public void writeObjectData(ByteBuffer byteBuffer, Object o) {
TBase thrift = (TBase) o;
try {
- byteBuffer.put(serializer.serialize(thrift));
+ byte[] serThrift = serializer.serialize(thrift);
+ IntSerializer.put(byteBuffer, serThrift.length, true);
+ byteBuffer.put(serThrift);
} catch (TException e) {
throw new RuntimeException(e);
}
}
@Override public <T> T readObjectData(ByteBuffer byteBuffer, Class<T> tClass) {
try {
- byte[] barr = new byte[byteBuffer.remaining()];
TBase prototype = (TBase) tClass.newInstance();
+ int tSize = IntSerializer.get(byteBuffer, true);
+ byte[] barr = new byte[tSize];
+ byteBuffer.get(barr);
deserializer.deserialize(prototype, barr);
return (T) prototype;
} catch (Exception e) {

0 comments on commit 066ee72

Please sign in to comment.