Exemplo n.º 1
0
        /// <inheritdoc />
        public override async Task Write(string value, NpgsqlWriteBuffer buf, NpgsqlLengthCache?lengthCache, NpgsqlParameter?parameter, bool async, CancellationToken cancellationToken = default)
        {
            if (buf.WriteSpaceLeft < 1)
            {
                await buf.Flush(async, cancellationToken);
            }

            buf.WriteByte(JsonPathVersion);

            await _textHandler.Write(value, buf, lengthCache, parameter, async, cancellationToken);
        }
Exemplo n.º 2
0
 public bool Write(ref DirectBuffer directBuf)
 {
     if (!_handledVersion)
     {
         if (_buf.WriteSpaceLeft < 1)
         {
             return(false);
         }
         _buf.WriteByte(ProtocolVersion);
         _handledVersion = true;
     }
     if (!_textHandler.Write(ref directBuf))
     {
         return(false);
     }
     _buf = null;
     return(true);
 }
Exemplo n.º 3
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();
            }
        }