Skip to content

Commit 7bb4db6

Browse files
committed
serialize 2 dim byte arrays
1 parent a213616 commit 7bb4db6

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/net/sharksystem/asap/utils/ASAPSerialization.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package net.sharksystem.asap.utils;
22

3-
import net.sharksystem.asap.ASAPHopImpl;
4-
import net.sharksystem.asap.ASAPException;
5-
import net.sharksystem.asap.ASAPHop;
6-
import net.sharksystem.asap.EncounterConnectionType;
3+
import net.sharksystem.asap.*;
74
import net.sharksystem.utils.Log;
85

96
import java.io.*;
@@ -41,6 +38,30 @@ public static byte[] readByteArray(InputStream is) throws IOException, ASAPExcep
4138
return messageBytes;
4239
}
4340

41+
public static void writeByteArray(byte[][] bytes2Dim, OutputStream os) throws IOException {
42+
if(bytes2Dim == null) {
43+
writeNonNegativeIntegerParameter(0, os);
44+
} else {
45+
writeNonNegativeIntegerParameter(bytes2Dim.length, os);
46+
for(int i = 0; i < bytes2Dim.length; i++) {
47+
ASAPSerialization.writeByteArray(bytes2Dim[i], os);
48+
}
49+
}
50+
}
51+
52+
public static byte[][] readByte2DimArray(InputStream is) throws IOException, ASAPException {
53+
// read len
54+
int len = readIntegerParameter(is);
55+
if(len == 0) return new byte[0][];
56+
57+
byte[][] messageBytes = new byte[len][];
58+
for(int i = 0; i < len; i++) {
59+
messageBytes[i] = ASAPSerialization.readByteArray(is);
60+
}
61+
62+
return messageBytes;
63+
}
64+
4465
public static void writeCharSequenceParameter(CharSequence parameter, OutputStream os) throws IOException {
4566
if(parameter == null || parameter.length() < 1) return;
4667
byte[] bytes = parameter.toString().getBytes();

0 commit comments

Comments
 (0)