feed method
Append chunk to the internal buffer and return any items that became
fully available. The returned list may be empty if the chunk only
completed part of a frame.
Throws FormatException if a frame declares an unknown tag.
Implementation
List<MultiResultItem> feed(Uint8List chunk) {
if (chunk.isEmpty) return const [];
final items = <MultiResultItem>[];
// Most native stream chunks contain one or more complete frames. Decode
// those directly to avoid copying the chunk into the accumulator. Only a
// trailing partial frame needs buffered assembly.
if (_buffer.length == 0) {
var offset = 0;
while (chunk.length - offset >= _frameHeaderSize) {
final tag = chunk[offset];
final len = _readUint32Le(chunk, offset + 1);
final frameEnd = offset + _frameHeaderSize + len;
if (frameEnd > chunk.length) break;
final payload = len == 0
? Uint8List(0)
: Uint8List.sublistView(chunk, offset + _frameHeaderSize, frameEnd);
_decodeItem(items, tag, payload);
offset = frameEnd;
}
if (offset < chunk.length) {
_buffer.add(Uint8List.sublistView(chunk, offset));
}
} else {
_buffer.add(chunk);
}
items.addAll(_drainCompleteFrames());
_itemsDecoded += items.length;
return items;
}