示例#1
0
        public Utf8Json(JsonReaderState initialState)
        {
            _state = initialState;

            if (_state._lineNumber < 1)
            {
                ThrowArgumentException("Invalid line number. Line number must be >= 1.");
            }

            if (_state._currentDepth < 0)
            {
                ThrowArgumentException("Invalid depth. Depth must be positive.");
            }

            if (_state._position < 0)
            {
                ThrowArgumentException("Invalid position. Position must be positive.");
            }

            _readerOptions = new JsonReaderOptions(JsonReaderOptions.CommentHandling.Default);
            _maxDepth      = StackFreeMaxDepth;
        }
示例#2
0
        public Utf8JsonReader(ReadOnlySpan <byte> data, bool isFinalBlock, JsonReaderState state = default)
        {
            if (!state.IsDefault)
            {
                _containerMask = state._containerMask;
                Depth          = state._depth;
                _inObject      = state._inObject;
                _stack         = state._stack;
                TokenType      = state._tokenType;
                _lineNumber    = state._lineNumber;
                _position      = state._position;
            }
            else
            {
                _containerMask = 0;
                Depth          = 0;
                _inObject      = false;
                _stack         = null;
                TokenType      = JsonTokenType.None;
                _lineNumber    = 1;
                _position      = 0;
            }

            _isFinalBlock = isFinalBlock;

            _reader          = default;
            _isSingleSegment = true;
            _buffer          = data;
            CurrentIndex     = 0;
            TokenStartIndex  = CurrentIndex;
            _maxDepth        = StackFreeMaxDepth;
            Value            = ReadOnlySpan <byte> .Empty;
            ValueType        = JsonValueType.Unknown;
            _isSingleValue   = true;
            Instrument       = false;
        }