pack method

  1. @override
Uint8List pack()
override

pack() should produce a message data payload that can be parsed by a corresponding parser in the frameside application (Lua) TxMsg needs to know its own message code, but it is not included in the payload bytes returned by pack; the 0x01 data byte and the msgCode byte are prepended to each bluetooth write() call by the sendDataRaw method, followed by the maximum amount of payload data that will fit until the whole message is sent.

Implementation

@override
Uint8List pack() {
  final stringBytes = utf8.encode(_text);
  final strlen = stringBytes.length;

  Uint8List bytes = Uint8List(6 + strlen);
  bytes[0] = _x >> 8;   // x msb
  bytes[1] = _x & 0xFF; // x lsb
  bytes[2] = _y >> 8;   // y msb
  bytes[3] = _y & 0xFF; // y lsb
  bytes[4] = _paletteOffset & 0x0F; // 1..15
  bytes[5] = _spacing & 0xFF;
  bytes.setRange(6, strlen + 6, stringBytes);

  return bytes;
}