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,11 +342,17 @@ 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()) {
Object[] array = (Object[]) actual; if (formal.getComponentType() == byte.class) {
Class<?> componentType = formal.getComponentType(); byte[] array = (byte[]) actual;
data.writeInt(array.length); data.writeInt(array.length);
for (Object element : array) { data.writeBytes(array);
writePrimitive(data, componentType, element); } else {
Object[] array = (Object[]) actual;
Class<?> componentType = formal.getComponentType();
data.writeInt(array.length);
for (Object element : array) {
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();
Class<?> componentType = formal.getComponentType();
Object[] a = (Object[]) Array.newInstance(componentType, size); if (formal.getComponentType() == byte.class) {
for (int z = 0; z < size; z++) { byte[] array = new byte[size];
readPrimitive(data, componentType, a, z); data.readBytes(array);
actuals[i] = array;
} else {
Class<?> componentType = formal.getComponentType();
Object[] a = (Object[]) Array.newInstance(componentType, size);
for (int z = 0; z < size; z++) {
readPrimitive(data, componentType, a, z);
}
actuals[i] = a;
} }
actuals[i] = a;
} else { } else {
return false; return false;
} }