fixed handling of byte arrays

This commit is contained in:
SpaceToad 2014-07-05 14:06:10 +02:00
parent 57c338b9af
commit 72b1a3cfe6

View file

@ -342,12 +342,18 @@ public final class RPCHandler {
} else if (String.class.equals(formal)) { } else if (String.class.equals(formal)) {
Utils.writeUTF(data, (String) actual); Utils.writeUTF(data, (String) actual);
} else if (formal.isArray()) { } else if (formal.isArray()) {
if (formal.getComponentType() == byte.class) {
byte[] array = (byte[]) actual;
data.writeInt(array.length);
data.writeBytes(array);
} else {
Object[] array = (Object[]) actual; Object[] array = (Object[]) actual;
Class<?> componentType = formal.getComponentType(); Class<?> componentType = formal.getComponentType();
data.writeInt(array.length); data.writeInt(array.length);
for (Object element : array) { for (Object element : array) {
writePrimitive(data, componentType, element); writePrimitive(data, componentType, element);
} }
}
} else { } else {
return false; return false;
} }
@ -407,12 +413,19 @@ public final class RPCHandler {
actuals[i] = Utils.readUTF(data); actuals[i] = Utils.readUTF(data);
} else if (formal.isArray()) { } else if (formal.isArray()) {
final int size = data.readInt(); final int size = data.readInt();
if (formal.getComponentType() == byte.class) {
byte[] array = new byte[size];
data.readBytes(array);
actuals[i] = array;
} else {
Class<?> componentType = formal.getComponentType(); Class<?> componentType = formal.getComponentType();
Object[] a = (Object[]) Array.newInstance(componentType, size); Object[] a = (Object[]) Array.newInstance(componentType, size);
for (int z = 0; z < size; z++) { for (int z = 0; z < size; z++) {
readPrimitive(data, componentType, a, z); readPrimitive(data, componentType, a, z);
} }
actuals[i] = a; actuals[i] = a;
}
} else { } else {
return false; return false;
} }