Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Only read the number of bytes needed in thrift

  • Loading branch information...
commit c2a5e31231e78b76ca1e10799be70c2046cb8e10 1 parent 9e902d4
@johnynek authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/jvm/meatlocker/TBaseSerializer.java
View
9 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,7 +17,9 @@
@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);
}
@@ -24,8 +27,10 @@
@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) {
Please sign in to comment.
Something went wrong with that request. Please try again.