add method

  1. @override
int add(
  1. List<int> data,
  2. int offset
)
override

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 (_nullOffset > 0) {
      if (byte != _nullTokens[_nullOffset]) {
        throw CodableException.unexpectedType(expected: 'null', actual: String.fromCharCode(byte));
      }
      _nullOffset++;
      if (_nullOffset == 4) {
        onValue(null);
        _isDone = true;
        return o + 1; // Return the next offset after the null value.
      }
      continue; // Continue to the next byte.
    } else if (byte == tokenN) {
      _nullOffset++;
      continue; // Start reading null.
    } else {
      parent.decodeObject(onValue, using: using);
      _isDone = true;
      return o; // Return the current offset, which is the first byte of the value.
    }
  }

  return data.length; // All bytes processed, no more entries.
}