add method
Implementation
@override
int add(List<int> data, int offset) {
while (offset < data.length && data[offset] <= tokenSpace) {
offset++;
}
if (offset >= data.length) {
return offset; // No more bytes to process.
}
for (int o = offset; o < data.length; o++) {
final byte = data[o];
if (byte == tokenRBracket) {
done();
_isDone = true;
return o + 1; // Return the next offset after the closing bracket.
}
if (_isItem) {
onItem(parent);
_isItem = false;
return o; // Return the current offset, which is the first byte of the next item.
}
if (byte == tokenLBracket || byte == tokenComma) {
_isItem = true;
continue; // Continue to the next byte.
}
throw StateError('Unexpected byte "${String.fromCharCode(byte)}" in IteratedJsonConsumer');
}
return data.length; // All bytes processed, no more items.
}