onData method

void onData(
  1. Uint8List data
)

Implementation

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

  while (((_partial.length - terminator!.length) > 0)) {
    int index = wildcardFind(terminator, _partial);
    if (index < 0) {
      break;
    }
    Uint8List message;
    if (stripTerminator) {
      message = Uint8List.fromList(_partial.take(index).toList());
    } else {
      message = Uint8List.fromList(
          _partial.take(index + terminator!.length).toList());
    }
    _controller.add(String.fromCharCodes(message));
    _partial = _partial.sublist(index + terminator!.length);
  }
}