toBytes method
Serializes the command to bytes.
Implementation
Uint8List toBytes() {
final codeBytes = _codeToBytes(code);
final recordLength = 8 + data.length;
if (recordLength > 0xFFFF) {
throw ArgumentError('ATEM command is too large: $recordLength bytes');
}
// ATEM command records begin with a big-endian 16-bit record length and
// two reserved bytes, followed by the command code and its payload.
final result = Uint8List(recordLength);
final header = ByteData.view(result.buffer);
header.setUint16(0, recordLength);
result.setRange(4, 8, codeBytes);
result.setRange(8, result.length, data);
return result;
}