skipRemainingKeys method

  1. @override
void skipRemainingKeys()
override

Skips the remaining key-value pairs in the collection.

This is useful when the Decodable implementation is not interested in the remaining key-value pairs. It must be called when nextKey is not used exhaustively.

Implementation

@override
void skipRemainingKeys() {
  var level = 1;
  var i = _offset;
  while (true) {
    switch (buffer[i++]) {
      case tokenDoubleQuote: // If inside string, skip it
        _offset = i;
        _skipString();
        i = _offset;
        break;
      case tokenLBrace: // If open symbol, increase level
        level++;
        break;
      case tokenRBrace: // If close symbol, decrease level
        level--;

        // If we have returned to the original level, we're done
        if (level == 0) {
          _offset = i;
          return;
        }
        break;
    }
  }
}