Skip to content

Commit

Permalink
Kryo doesn't work since bump up a newer version
Browse files Browse the repository at this point in the history
  • Loading branch information
coderplay committed Jul 16, 2015
1 parent 9d88d76 commit ed98c8d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,23 @@
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.serializers.DefaultArraySerializers;

/**
* RequestObject Serializer
*
*/
public class RequestObjectSerializer extends Serializer<RequestObject> {
/**
* @param kryo
* @param output
* @param reqObject
*/
@Override
public void write(Kryo kryo, Output output, RequestObject reqObject) {
byte[] content = reqObject.getBytes();
output.write(content);
}
private DefaultArraySerializers.ByteArraySerializer delegate = new DefaultArraySerializers.ByteArraySerializer();

/**
* @param kryo
* @param input
* @param type
* @return
*/
public RequestObject create(Kryo kryo, Input input, Class<RequestObject> type) {
return new RequestObject(input.getBuffer().length - 1);
}
@Override
public void write(Kryo kryo, Output output, RequestObject reqObject) {
delegate.write(kryo, output, reqObject.getBytes());
}

@Override
public RequestObject read(Kryo kryo, Input input, Class<RequestObject> type) {
return kryo.readObjectOrNull(input, type);
byte[] bytes = delegate.read(kryo, input, byte[].class);
return new RequestObject(bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public ResponseObject(int size){
bytes = new byte[size];
}

public ResponseObject(byte[] bytes){
this.bytes = bytes;
}
public byte[] getBytes() {
return bytes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,25 @@
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.serializers.DefaultArraySerializers;

/**
* ResponseObject Serializer
*
*/
public class ResponseObjectSerializer extends Serializer<ResponseObject> {
/**
* @param kryo
* @param output
* @param resObject
*/
@Override
public void write(Kryo kryo, Output output, ResponseObject resObject) {
byte[] content = resObject.getBytes();
output.write(content);
}

/**
* @param kryo
* @param input
* @param type
* @return
*/
public ResponseObject create(Kryo kryo, Input input, Class<ResponseObject> type) {
return new ResponseObject(input.getBuffer().length - 1);
private DefaultArraySerializers.ByteArraySerializer delegate = new DefaultArraySerializers.ByteArraySerializer();

@Override
public void write(Kryo kryo, Output output, ResponseObject resObject) {
delegate.write(kryo, output, resObject.getBytes());
}

@Override
public ResponseObject read(Kryo kryo, Input input,
Class<ResponseObject> type) {
return kryo.readObjectOrNull(input, type);
byte[] bytes = delegate.read(kryo, input, byte[].class);
return new ResponseObject(bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class KryoEncoder implements Encoder {
*/
@Override
public byte[] encode(Object object) throws Exception {
Output output = new Output(256);
Output output = new Output(256, Integer.MAX_VALUE);
KryoUtils.getKryo().writeClassAndObject(output, object);
return output.toBytes();
}
Expand Down

0 comments on commit ed98c8d

Please sign in to comment.