예제 #1
0
        public override async ValueTask <Dictionary <string, string> > Read(ReadBuffer buf, int len, bool async, FieldDescription fieldDescription)
        {
            await buf.Ensure(4, async);

            var numElements = buf.ReadInt32();
            var hstore      = new Dictionary <string, string>(numElements);

            for (var i = 0; i < numElements; i++)
            {
                await buf.Ensure(4, async);

                var keyLen = buf.ReadInt32();
                Debug.Assert(keyLen != -1);
                var key = await _textHandler.Read(buf, keyLen, async);

                await buf.Ensure(4, async);

                var valueLen = buf.ReadInt32();

                hstore[key] = valueLen == -1
                    ? null
                    : await _textHandler.Read(buf, valueLen, async);
            }
            return(hstore);
        }
예제 #2
0
        async ValueTask <T> ReadInto <T>(T dictionary, int numElements, NpgsqlReadBuffer buf, bool async, CancellationToken cancellationToken = default)
            where T : IDictionary <string, string?>
        {
            for (var i = 0; i < numElements; i++)
            {
                await buf.Ensure(4, async, cancellationToken);

                var keyLen = buf.ReadInt32();
                Debug.Assert(keyLen != -1);
                var key = await _textHandler.Read(buf, keyLen, async, cancellationToken : cancellationToken);

                await buf.Ensure(4, async, cancellationToken);

                var valueLen = buf.ReadInt32();

                dictionary[key] = valueLen == -1
                    ? null
                    : await _textHandler.Read(buf, valueLen, async, cancellationToken : cancellationToken);
            }
            return(dictionary);
        }
예제 #3
0
        /// <inheritdoc />
        public override async ValueTask <string> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription = null, CancellationToken cancellationToken = default)
        {
            await buf.Ensure(1, async, cancellationToken);

            var version = buf.ReadByte();

            if (version != JsonPathVersion)
            {
                throw new NotSupportedException($"Don't know how to decode JSONPATH with wire format {version}, your connection is now broken");
            }

            return(await _textHandler.Read(buf, len - 1, async, fieldDescription, cancellationToken));
        }
예제 #4
0
        public bool Read(out string result)
        {
            if (!_handledVersion)
            {
                if (_buf.ReadBytesLeft < 1)
                {
                    result = null;
                    return(false);
                }
                var version = _buf.ReadByte();
                if (version != 1)
                {
                    throw new NotSupportedException(String.Format("Don't know how to decode JSONB with wire format {0}, your connection is now broken", version));
                }
                _handledVersion = true;
            }

            if (!_textHandler.Read(out result))
            {
                return(false);
            }
            _buf = null;
            return(true);
        }
예제 #5
0
        public override bool Read([CanBeNull] out string result)
        {
            if (!_handledVersion)
            {
                if (_readBuf.ReadBytesLeft < 1)
                {
                    result = null;
                    return(false);
                }
                var version = _readBuf.ReadByte();
                if (version != JsonbProtocolVersion)
                {
                    throw new NotSupportedException($"Don't know how to decode JSONB with wire format {version}, your connection is now broken");
                }
                _handledVersion = true;
            }

            if (!_textHandler.Read(out result))
            {
                return(false);
            }
            _readBuf = null;
            return(true);
        }
예제 #6
0
        public bool Read(out IDictionary <string, string> result)
        {
            result = null;
            switch (_state)
            {
            case State.Count:
                if (_buf.ReadBytesLeft < 4)
                {
                    return(false);
                }
                _numElements = _buf.ReadInt32();
                _value       = new Dictionary <string, string>(_numElements);
                if (_numElements == 0)
                {
                    CleanupState();
                    return(true);
                }
                goto case State.KeyLen;

            case State.KeyLen:
                _state = State.KeyLen;
                if (_buf.ReadBytesLeft < 4)
                {
                    return(false);
                }
                var keyLen = _buf.ReadInt32();
                Contract.Assume(keyLen != -1);
                _textHandler.PrepareRead(_buf, _fieldDescription, keyLen);
                goto case State.KeyData;

            case State.KeyData:
                _state = State.KeyData;
                if (!_textHandler.Read(out _key))
                {
                    return(false);
                }
                goto case State.ValueLen;

            case State.ValueLen:
                _state = State.ValueLen;
                if (_buf.ReadBytesLeft < 4)
                {
                    return(false);
                }
                var valueLen = _buf.ReadInt32();
                if (valueLen == -1)
                {
                    _value[_key] = null;
                    if (--_numElements == 0)
                    {
                        result = _value;
                        CleanupState();
                        return(true);
                    }
                    goto case State.KeyLen;
                }
                _textHandler.PrepareRead(_buf, _fieldDescription, valueLen);
                goto case State.ValueData;

            case State.ValueData:
                _state = State.ValueData;
                string value;
                if (!_textHandler.Read(out value))
                {
                    return(false);
                }
                _value[_key] = value;
                if (--_numElements == 0)
                {
                    result = _value;
                    CleanupState();
                    return(true);
                }
                goto case State.KeyLen;

            default:
                throw PGUtil.ThrowIfReached();
            }
        }