Beispiel #1
0
 public void PrepareWrite(object value, NpgsqlBuffer buf, LengthCache lengthCache, NpgsqlParameter parameter)
 {
     _textHandler.PrepareWrite(value, buf, lengthCache, parameter);
     _buf            = buf;
     _handledVersion = false;
 }
Beispiel #2
0
        public bool Write(ref DirectBuffer directBuf)
        {
            switch (_state)
            {
            case State.Count:
                if (_buf.WriteSpaceLeft < 4)
                {
                    return(false);
                }
                _buf.WriteInt32(_value.Count);
                if (_value.Count == 0)
                {
                    CleanupState();
                    return(true);
                }
                _enumerator = _value.GetEnumerator();
                _enumerator.MoveNext();
                goto case State.KeyLen;

            case State.KeyLen:
                _state = State.KeyLen;
                if (_buf.WriteSpaceLeft < 4)
                {
                    return(false);
                }
                var keyLen = _lengthCache.Get();
                _buf.WriteInt32(keyLen);
                _textHandler.PrepareWrite(_enumerator.Current.Key, _buf, _lengthCache, _parameter);
                goto case State.KeyData;

            case State.KeyData:
                _state = State.KeyData;
                if (!_textHandler.Write(ref directBuf))
                {
                    return(false);
                }
                goto case State.ValueLen;

            case State.ValueLen:
                _state = State.ValueLen;
                if (_buf.WriteSpaceLeft < 4)
                {
                    return(false);
                }
                if (_enumerator.Current.Value == null)
                {
                    _buf.WriteInt32(-1);
                    if (!_enumerator.MoveNext())
                    {
                        CleanupState();
                        return(true);
                    }
                    goto case State.KeyLen;
                }
                var valueLen = _lengthCache.Get();
                _buf.WriteInt32(valueLen);
                _textHandler.PrepareWrite(_enumerator.Current.Value, _buf, _lengthCache, _parameter);
                goto case State.ValueData;

            case State.ValueData:
                _state = State.ValueData;
                if (!_textHandler.Write(ref directBuf))
                {
                    return(false);
                }
                if (!_enumerator.MoveNext())
                {
                    CleanupState();
                    return(true);
                }
                goto case State.KeyLen;

            default:
                throw PGUtil.ThrowIfReached();
            }
        }