onData method

void onData(
  1. Uint8List data
)

Implementation

void onData(Uint8List data) {
  _dataSinceLastTick = true;
  if (_partial.length > maxLen) {
    _partial = _partial.sublist(_partial.length - maxLen);
  }

  _partial.addAll(data);

  while (_partial.length > 0) {
    int index = wildcardFind(header, _partial);
    if (index < 0) {
      return;
    }

    if (index > 0) {
      _partial = _partial.sublist(index);
    }

    if (_partial.length < header!.length + 1) {
      // not completely arrived yet.
      return;
    }

    int len = _partial[header!.length];
    if (_partial.length < len + header!.length + 1) {
      // not completely arrived yet.
      return;
    }

    _controller.add(
        Uint8List.fromList(_partial.sublist(0, len + header!.length + 1)));
    _partial = _partial.sublist(len + header!.length + 1);
  }
}