//check if the converted from bytes id is greater than -1
//-1 is only used if the authentication is not successful in the id field of the SERVERDATA_AUTH_RESPONSE packet
int packetId = ByteConversions.littleEndianToInt(Arrays.copyOfRange(bytes, 0, 4));
if (packetId < -1) {
throw new UnexpectedValueException("the packetId must be an integer greater than -1.");
}
//check if the converted from bytes type is one of the expected.
int packetType = ByteConversions.littleEndianToInt(Arrays.copyOfRange(bytes, 4, 8));
if ((packetType != SERVERDATA_AUTH) && (packetType != SERVERDATA_EXECCOMMAND) &&
(packetType != SERVERDATA_RESPONSE_VALUE) && (packetType != SERVERDATA_AUTH_RESPONSE)) {
throw new UnexpectedValueException("the packetType must be the value of one of the SERVERDATA_* values");
}
//construct the packet body. we exclude the final 2 bytes as we already now they should be '\0'.
String response = new String(Arrays.copyOfRange(bytes, 8, bytes.length - 2));