Exemple #1
0
        private bool ContinueParsingValue()
        {
            switch (_state.Continuation)
            {
            case JsonParserTokenContinuation.PartialNegativeInfinity:
                // here we need to check if we have a negative number or negative
                // infinity
                if (_expectedTokenBufferPosition == 1 &&
                    _inputBuffer[_pos] != (byte)'I')
                {
                    _zeroPrefix         = false;
                    _isNegative         = true;
                    _isFractionedDouble = false;
                    _isOverflow         = false;
                    _isExponent         = false;
                    _state.Long         = 0;
                    _state.EscapePositions.Clear();
                    _unmanagedWriteBuffer.Clear();
                    _unmanagedWriteBuffer.WriteByte((byte)'-');
                    _state.Continuation = JsonParserTokenContinuation.PartialNumber;
                    goto case JsonParserTokenContinuation.PartialNumber;
                }
                goto case JsonParserTokenContinuation.PartialPositiveInfinity;

            case JsonParserTokenContinuation.PartialNaN:
            case JsonParserTokenContinuation.PartialPositiveInfinity:
            {
                if (EnsureRestOfToken(ref _pos) == false)
                {
                    return(false);
                }

                _state.Continuation     = JsonParserTokenContinuation.None;
                _state.CurrentTokenType = JsonParserToken.Float;
                _unmanagedWriteBuffer.Write(_expectedTokenBuffer, 0, _expectedTokenBuffer.Length);
                _unmanagedWriteBuffer.EnsureSingleChunk(_state);

                return(true);
            }

            case JsonParserTokenContinuation.PartialNumber:
            {
                if (ParseNumber(ref _state.Long, ref _pos) == false)
                {
                    return(false);
                }

                if (_state.CurrentTokenType == JsonParserToken.Float)
                {
                    _unmanagedWriteBuffer.EnsureSingleChunk(_state);
                }

                _state.Continuation = JsonParserTokenContinuation.None;

                return(true);
            }

            case JsonParserTokenContinuation.PartialPreamble:
            {
                if (EnsureRestOfToken(ref _pos) == false)
                {
                    return(false);
                }

                _state.Continuation = JsonParserTokenContinuation.None;

                return(false);
            }

            case JsonParserTokenContinuation.PartialString:
            {
                if (ParseString(ref _pos) == false)
                {
                    return(false);
                }

                _unmanagedWriteBuffer.EnsureSingleChunk(_state);
                _state.CurrentTokenType = JsonParserToken.String;
                _state.Continuation     = JsonParserTokenContinuation.None;

                return(true);
            }

            case JsonParserTokenContinuation.PartialFalse:
            {
                if (EnsureRestOfToken(ref _pos) == false)
                {
                    return(false);
                }

                _state.CurrentTokenType = JsonParserToken.False;
                _state.Continuation     = JsonParserTokenContinuation.None;

                return(true);
            }

            case JsonParserTokenContinuation.PartialTrue:
            {
                if (EnsureRestOfToken(ref _pos) == false)
                {
                    return(false);
                }

                _state.CurrentTokenType = JsonParserToken.True;
                _state.Continuation     = JsonParserTokenContinuation.None;

                return(true);
            }

            case JsonParserTokenContinuation.PartialNull:
            {
                if (EnsureRestOfToken(ref _pos) == false)
                {
                    return(false);
                }

                _state.CurrentTokenType = JsonParserToken.Null;
                _state.Continuation     = JsonParserTokenContinuation.None;

                return(true);
            }

            default:
                ThrowException("Somehow got continuation for single byte token " + _state.Continuation);
                return(false);    // never hit
            }
        }
Exemple #2
0
 public void Write(bool b)
 {
     _buffer.WriteByte(b ? (byte)1 : (byte)2);
 }