def _AcceptResponses(self, expected_header, info_cb, timeout_ms=None):
    while True:
      response = self.usb.BulkRead(64, timeout_ms=timeout_ms)
      header = response[:4]
      remaining = response[4:]

      if header == 'INFO':
        info_cb(FastbootMessage(remaining, header))
      elif header in self.FINAL_HEADERS:
        if header != expected_header:
          raise FastbootStateMismatch(
              'Expected %s, got %s', expected_header, header)
        if header == 'OKAY':
          info_cb(FastbootMessage(remaining, header))
        return remaining
      elif header == 'FAIL':
        info_cb(FastbootMessage(remaining, header))
        raise FastbootRemoteFailure('FAIL: %s', remaining)
      else:
        raise FastbootInvalidResponse(
            'Got unknown header %s and response %s', header, remaining)
Accepts responses until the expected header or a FAIL.
dataset/ETHPy150Open google/python-adb/adb/fastboot.py/FastbootProtocol._AcceptResponses