class GattSerialMessage {

    public static byte[] parse(byte[] payload) {
        int length = (payload[0] & 0xff);
        Buffer buffer = new Buffer();
        buffer.write(payload, 2, length);
        int crc = computeCRC16(payload, 0, payload.length - 2);
        int checkCrc = (((payload[payload.length - 1] & 0xff) << 8)) + (payload[payload.length - 2] & 0xff);
        if (crc != checkCrc) {
            Log.w(TAG, "Checksum failed");
            throw new IllegalStateException("Checksum mismatch");
        }
        return buffer.readByteArray();
    }

    private  GattSerialMessage(Buffer buffer);

}