LOGGER.error("Unexpected error: ", e);
throw new RuntimeException(e);
}
});
} else if (type == long[].class) {
PacketArray packetArray = field.getAnnotation(PacketArray.class);
final boolean constant = packetArray.constant();
final int constantLength = packetArray.size();
writeActions.add((packet, buffer) -> {
try {
long[] data = (long[]) field.get(packet);
if (!constant) {
buffer.writeShort(data.length);
} else {
// Verify the length of the constant packet
if (data.length != constantLength) {
throw new RuntimeException("The length of the constant array doesn't match the annotation");
}
}
RawConverter.writeUnsignedIntArray(data, buffer);
} catch (IllegalArgumentException | IllegalAccessException e) {
// should never happen
LOGGER.error("Unexpected error: ", e);
throw new RuntimeException(e);
}
});
} else if (type == int[].class) {
PacketArray packetArray = field.getAnnotation(PacketArray.class);
final boolean constant = packetArray.constant();
writeActions.add((packet, buffer) -> {
try {
if (!constant) {
buffer.writeShort(((int[]) field.get(packet)).length);
}
RawConverter.writeUnsignedShortArray((int[]) field.get(packet), buffer);
} catch (IllegalArgumentException | IllegalAccessException e) {
// should never happen
LOGGER.error("Unexpected error: ", e);
throw new RuntimeException(e);
}
});
} else if (type == short[].class) {
PacketArray packetArray = field.getAnnotation(PacketArray.class);
final boolean constant = packetArray.constant();
writeActions.add((packet, buffer) -> {
try {
if (!constant) {
buffer.writeShort(((short[]) field.get(packet)).length);
}