private unsafe void ReadJsonValueUnlikely <TWriteStrategy>(JsonParserToken current) where TWriteStrategy : IWriteStrategy
        {
            int start;

            switch (current)
            {
            case JsonParserToken.StartArray:
                _continuationState.Push(new BuildingState(ContinuationState.ReadArray));
                return;

            case JsonParserToken.Float:
                if ((_mode & UsageMode.ValidateDouble) == UsageMode.ValidateDouble)
                {
                    _reader.ValidateFloat();
                }

                if (typeof(TWriteStrategy) == typeof(WriteNone))
                {
                    start = _writer.WriteValue(_state.StringBuffer, _state.StringSize);
                }
                else
                {
                    start = _writer.WriteValue(_state.StringBuffer, _state.StringSize, out _, _mode, _state.CompressedSize);
                }

                _state.CompressedSize = null;
                _writeToken           = new WriteToken(start, BlittableJsonToken.LazyNumber);
                return;

            case JsonParserToken.True:
            case JsonParserToken.False:
                start       = _writer.WriteValue(current == JsonParserToken.True ? (byte)1 : (byte)0);
                _writeToken = new WriteToken(start, BlittableJsonToken.Boolean);
                return;

            case JsonParserToken.Null:
                // nothing to do here, we handle that with the token
                start       = _writer.WriteValue((byte)0);
                _writeToken = new WriteToken(start, BlittableJsonToken.Null);
                return;
            }

            ThrowExpectedValue(current);
        }
        private void ReadJsonValue()
        {
            var start = _position;

            switch (_state.CurrentTokenType)
            {
            case JsonParserToken.StartObject:
                _continuationState.Push(new BuildingState
                {
                    State = ContinuationState.ReadObject
                });
                return;

            case JsonParserToken.StartArray:
                _continuationState.Push(new BuildingState
                {
                    State = ContinuationState.ReadArray
                });
                return;

            case JsonParserToken.Integer:
                _position  += WriteVariableSizeLong(_state.Long);
                _writeToken = new WriteToken
                {
                    ValuePos     = start,
                    WrittenToken = BlittableJsonToken.Integer
                };
                return;

            case JsonParserToken.Float:
                if ((_mode & UsageMode.ValidateDouble) == UsageMode.ValidateDouble)
                {
                    _reader.ValidateFloat();
                }
                BlittableJsonToken ignored;
                WriteStringFromReader(out ignored);
                _writeToken = new WriteToken
                {
                    ValuePos     = start,
                    WrittenToken = BlittableJsonToken.Float
                };
                return;

            case JsonParserToken.String:
                BlittableJsonToken stringToken;
                WriteStringFromReader(out stringToken);
                _writeToken = new WriteToken
                {
                    ValuePos     = start,
                    WrittenToken = stringToken
                };
                return;

            case JsonParserToken.True:
            case JsonParserToken.False:
                _stream.WriteByte(_state.CurrentTokenType == JsonParserToken.True ? (byte)1 : (byte)0);
                _position++;
                _writeToken = new WriteToken
                {
                    ValuePos     = start,
                    WrittenToken = BlittableJsonToken.Boolean
                };
                return;

            case JsonParserToken.Null:
                _stream.WriteByte(0);
                _position++;
                _writeToken = new WriteToken     // nothing to do here, we handle that with the token
                {
                    WrittenToken = BlittableJsonToken.Null,
                    ValuePos     = start
                };
                return;

            default:
                throw new InvalidDataException("Expected a value, but got " + _state.CurrentTokenType);
            }
        }
Exemple #3
0
        private unsafe void ReadJsonValue()
        {
            int start;

            switch (_state.CurrentTokenType)
            {
            case JsonParserToken.StartObject:
                _continuationState.Push(new BuildingState
                {
                    State = ContinuationState.ReadObject
                });
                return;

            case JsonParserToken.StartArray:
                _continuationState.Push(new BuildingState
                {
                    State = ContinuationState.ReadArray
                });
                return;

            case JsonParserToken.Integer:
                start       = _writer.WriteValue(_state.Long);
                _writeToken = new WriteToken
                {
                    ValuePos     = start,
                    WrittenToken = BlittableJsonToken.Integer
                };
                return;

            case JsonParserToken.Float:
                if ((_mode & UsageMode.ValidateDouble) == UsageMode.ValidateDouble)
                {
                    _reader.ValidateFloat();
                }
                BlittableJsonToken ignored;

                start = _writer.WriteValue(_state.StringBuffer, _state.StringSize, out ignored, _mode, _state.CompressedSize);
                _state.CompressedSize = null;
                _writeToken           = new WriteToken
                {
                    ValuePos     = start,
                    WrittenToken = BlittableJsonToken.Float
                };
                return;

            case JsonParserToken.String:
                BlittableJsonToken stringToken;
                start = _writer.WriteValue(_state.StringBuffer, _state.StringSize, _state.EscapePositions, out stringToken, _mode, _state.CompressedSize);
                _state.CompressedSize = null;
                _writeToken           = new WriteToken
                {
                    ValuePos     = start,
                    WrittenToken = stringToken
                };
                return;

            case JsonParserToken.True:
            case JsonParserToken.False:
                start       = _writer.WriteValue(_state.CurrentTokenType == JsonParserToken.True ? (byte)1 : (byte)0);
                _writeToken = new WriteToken
                {
                    ValuePos     = start,
                    WrittenToken = BlittableJsonToken.Boolean
                };
                return;

            case JsonParserToken.Null:
                start       = _writer.WriteValue((byte)0);
                _writeToken = new WriteToken     // nothing to do here, we handle that with the token
                {
                    WrittenToken = BlittableJsonToken.Null,
                    ValuePos     = start
                };
                return;

            default:
                throw new InvalidDataException("Expected a value, but got " + _state.CurrentTokenType);
            }
        }