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 == tokenRBrace) {
done();
_isDone = true;
return o + 1; // Return the next offset after the closing brace.
}
if (_isEntry) {
parent.decodeEager((d) {
_currentKey = d.decodeString();
});
_isEntry = false;
return o; // Return the current offset, which is the first byte of the key.
}
if (byte == tokenColon) {
assert(_currentKey != null, "No key was read before colon.");
onEntry(_currentKey!, parent);
_currentKey = null;
return o + 1; // Return the next offset after the colon.
}
if (byte == tokenLBrace || byte == tokenComma) {
_isEntry = true;
continue; // Continue to the next byte.
}
throw StateError('Unexpected byte "${String.fromCharCode(byte)}" in KeyedJsonConsumer');
}
return data.length; // All bytes processed, no more entries.
}