/** * "\0REQ" == [ 00 52 45 51 ] == 5391697 * * <p>"\0RES" == [ 00 52 45 53 ] == 5391699 * * @param bytes array of bytes containing magic code for a packet * @throws BadMagicException if byte array is not 4 bytes long */ public static GearmanPacketMagic fromBytes(byte[] bytes) { if (bytes != null && bytes.length == 4) { int magic = ByteUtils.fromBigEndian(bytes); if (magic == ByteUtils.fromBigEndian(REQ.toBytes())) { return REQ; } if (magic == ByteUtils.fromBigEndian(RES.toBytes())) { return RES; } } throw new BadMagicException(ByteUtils.toHex(bytes)); }