generateMessage static method

Uint8List generateMessage(
  1. int command,
  2. int arg0,
  3. int arg1,
  4. Uint8List? payload,
)

Implementation

static Uint8List generateMessage(int command, int arg0, int arg1, Uint8List? payload) {
  Uint8List message;

  if (payload != null) {
    message = Uint8List(ADB_HEADER_LENGTH + payload.length);
  } else {
    message = Uint8List(ADB_HEADER_LENGTH);
  }

  ByteData byteData = ByteData.view(message.buffer);

  byteData.setUint32(0, command, Endian.little);
  byteData.setUint32(4, arg0, Endian.little);
  byteData.setUint32(8, arg1, Endian.little);

  if (payload != null) {
    byteData.setUint32(12, payload.length, Endian.little);
    byteData.setUint32(16, generatePayloadChecksum(payload), Endian.little);
  } else {
    byteData.setUint32(12, 0, Endian.little);
    byteData.setUint32(16, 0, Endian.little);
  }

  byteData.setUint32(20, (~command).toUnsigned(command.bitLength + 1), Endian.little);

  if (payload != null) {
    message.setAll(ADB_HEADER_LENGTH, payload);
  }

  return message;
}