Example #1
0
 public void PrepareRead(NpgsqlBuffer buf, int len, FieldDescription fieldDescription)
 {
     // Subtract one byte for the version number
     _textHandler.PrepareRead(buf, fieldDescription, len - 1);
     _buf            = buf;
     _handledVersion = false;
 }
Example #2
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();
            }
        }