processSlip method
Removes bytes inserted by the SLIP protocol.
This function is here until package:osc
supports SLIP, mandated by the OSC v1.1 spec.
See this issue: https://github.com/pq/osc/issues/24
See: https://en.wikipedia.org/wiki/Serial_Line_Internet_Protocol
Implementation
Uint8List processSlip(List<int> data) {
const end = 192;
const esc = 219;
const escEnd = 220;
const escEsc = 221;
final newPacket = <int>[];
var prevElement = 0;
for (final element in data) {
if (prevElement == esc && element == escEnd) {
newPacket.last = end; // ESC + ESC_END -> END
} else if (prevElement == esc && element == escEsc) {
newPacket.last = esc; // ESC + ESC_ESC -> ESC
} else {
newPacket.add(element);
}
prevElement = element;
}
if (newPacket.last == end) newPacket.removeLast();
return Uint8List.fromList(newPacket);
}