File tree Expand file tree Collapse file tree 4 files changed +20
-40
lines changed
lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark
lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol Expand file tree Collapse file tree 4 files changed +20
-40
lines changed Original file line number Diff line number Diff line change 4
4
import com .esotericsoftware .kryo .Serializer ;
5
5
import com .esotericsoftware .kryo .io .Input ;
6
6
import com .esotericsoftware .kryo .io .Output ;
7
+ import com .esotericsoftware .kryo .serializers .DefaultArraySerializers ;
7
8
8
9
/**
9
10
* RequestObject Serializer
10
11
*
11
12
*/
12
13
public class RequestObjectSerializer extends Serializer <RequestObject > {
13
- /**
14
- * @param kryo
15
- * @param output
16
- * @param reqObject
17
- */
18
- @ Override
19
- public void write (Kryo kryo , Output output , RequestObject reqObject ) {
20
- byte [] content = reqObject .getBytes ();
21
- output .write (content );
22
- }
14
+ private DefaultArraySerializers .ByteArraySerializer delegate = new DefaultArraySerializers .ByteArraySerializer ();
23
15
24
- /**
25
- * @param kryo
26
- * @param input
27
- * @param type
28
- * @return
29
- */
30
- public RequestObject create (Kryo kryo , Input input , Class <RequestObject > type ) {
31
- return new RequestObject (input .getBuffer ().length - 1 );
32
- }
16
+ @ Override
17
+ public void write (Kryo kryo , Output output , RequestObject reqObject ) {
18
+ delegate .write (kryo , output , reqObject .getBytes ());
19
+ }
33
20
34
21
@ Override
35
22
public RequestObject read (Kryo kryo , Input input , Class <RequestObject > type ) {
36
- return kryo .readObjectOrNull (input , type );
23
+ byte [] bytes = delegate .read (kryo , input , byte [].class );
24
+ return new RequestObject (bytes );
37
25
}
38
26
}
Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ public ResponseObject(int size){
15
15
bytes = new byte [size ];
16
16
}
17
17
18
+ public ResponseObject (byte [] bytes ){
19
+ this .bytes = bytes ;
20
+ }
18
21
public byte [] getBytes () {
19
22
return bytes ;
20
23
}
Original file line number Diff line number Diff line change 4
4
import com .esotericsoftware .kryo .Serializer ;
5
5
import com .esotericsoftware .kryo .io .Input ;
6
6
import com .esotericsoftware .kryo .io .Output ;
7
+ import com .esotericsoftware .kryo .serializers .DefaultArraySerializers ;
7
8
8
9
/**
9
10
* ResponseObject Serializer
10
11
*
11
12
*/
12
13
public class ResponseObjectSerializer extends Serializer <ResponseObject > {
13
- /**
14
- * @param kryo
15
- * @param output
16
- * @param resObject
17
- */
18
- @ Override
19
- public void write (Kryo kryo , Output output , ResponseObject resObject ) {
20
- byte [] content = resObject .getBytes ();
21
- output .write (content );
22
- }
23
14
24
- /**
25
- * @param kryo
26
- * @param input
27
- * @param type
28
- * @return
29
- */
30
- public ResponseObject create (Kryo kryo , Input input , Class <ResponseObject > type ) {
31
- return new ResponseObject (input .getBuffer ().length - 1 );
15
+ private DefaultArraySerializers .ByteArraySerializer delegate = new DefaultArraySerializers .ByteArraySerializer ();
16
+
17
+ @ Override
18
+ public void write (Kryo kryo , Output output , ResponseObject resObject ) {
19
+ delegate .write (kryo , output , resObject .getBytes ());
32
20
}
33
21
34
22
@ Override
35
23
public ResponseObject read (Kryo kryo , Input input ,
36
24
Class <ResponseObject > type ) {
37
- return kryo .readObjectOrNull (input , type );
25
+ byte [] bytes = delegate .read (kryo , input , byte [].class );
26
+ return new ResponseObject (bytes );
38
27
}
39
28
}
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ public class KryoEncoder implements Encoder {
14
14
*/
15
15
@ Override
16
16
public byte [] encode (Object object ) throws Exception {
17
- Output output = new Output (256 );
17
+ Output output = new Output (256 , Integer . MAX_VALUE );
18
18
KryoUtils .getKryo ().writeClassAndObject (output , object );
19
19
return output .toBytes ();
20
20
}
You can’t perform that action at this time.
0 commit comments