示例#1
0
        internal void WriteChars(char[] chars, int offset, int len)
        {
            var charCount = len == 0 ? chars.Length : len;

            Debug.Assert(TextEncoding.GetByteCount(chars, 0, charCount) <= WriteSpaceLeft);
            WritePosition += TextEncoding.GetBytes(chars, offset, charCount, Buffer, WritePosition);
        }
示例#2
0
    internal async Task WriteParse(string sql, string statementName, List <NpgsqlParameter> inputParameters, bool async, CancellationToken cancellationToken = default)
    {
        Debug.Assert(statementName.All(c => c < 128));

        int queryByteLen;

        try
        {
            queryByteLen = TextEncoding.GetByteCount(sql);
        }
        catch (Exception e)
        {
            Break(e);
            throw;
        }

        if (WriteBuffer.WriteSpaceLeft < 1 + 4 + statementName.Length + 1)
        {
            await Flush(async, cancellationToken);
        }

        var messageLength =
            sizeof(byte) +                        // Message code
            sizeof(int) +                         // Length
            statementName.Length +                // Statement name
            sizeof(byte) +                        // Null terminator for the statement name
            queryByteLen + sizeof(byte) +         // SQL query length plus null terminator
            sizeof(ushort) +                      // Number of parameters
            inputParameters.Count * sizeof(int);  // Parameter OIDs

        WriteBuffer.WriteByte(FrontendMessageCode.Parse);
        WriteBuffer.WriteInt32(messageLength - 1);
        WriteBuffer.WriteNullTerminatedString(statementName);

        await WriteBuffer.WriteString(sql, queryByteLen, async, cancellationToken);

        if (WriteBuffer.WriteSpaceLeft < 1 + 2)
        {
            await Flush(async, cancellationToken);
        }
        WriteBuffer.WriteByte(0); // Null terminator for the query
        WriteBuffer.WriteUInt16((ushort)inputParameters.Count);

        foreach (var p in inputParameters)
        {
            if (WriteBuffer.WriteSpaceLeft < 4)
            {
                await Flush(async, cancellationToken);
            }

            WriteBuffer.WriteInt32((int)p.Handler !.PostgresType.OID);
        }
    }
        /// <summary>
        /// Initializes a new instance of the <c>LoginRequest</c> class with the given verification code.
        /// </summary>
        /// <param name="username">the username for the remote server.</param>
        /// <param name="password">the password to the account.</param>
        /// <param name="sessionKey">the session key for the current login session.</param>
        /// <exception cref="System.ArgumentNullException">The input username or password is null.</exception>
        public LoginRequestMessage(string username, string password, uint sessionKey)
        {
            if (username == null || password == null)
            {
                throw new ArgumentNullException("username or password cannot be null.");
            }

            m_username   = username;
            m_password   = password;
            m_sessionKey = sessionKey;

            m_verificatonCode = CreateVerificationCode();
            m_bodyLength      = TextEncoding.GetByteCount(m_verificatonCode);
        }
示例#4
0
    internal async Task WriteQuery(string sql, bool async, CancellationToken cancellationToken = default)
    {
        var queryByteLen = TextEncoding.GetByteCount(sql);

        if (WriteBuffer.WriteSpaceLeft < 1 + 4)
        {
            await Flush(async, cancellationToken);
        }

        WriteBuffer.WriteByte(FrontendMessageCode.Query);
        WriteBuffer.WriteInt32(
            sizeof(int) +         // Message length (including self excluding code)
            queryByteLen +        // Query byte length
            sizeof(byte));        // Null terminator

        await WriteBuffer.WriteString(sql, queryByteLen, async, cancellationToken);

        if (WriteBuffer.WriteSpaceLeft < 1)
        {
            await Flush(async, cancellationToken);
        }
        WriteBuffer.WriteByte(0);  // Null terminator
    }
示例#5
0
 internal void WriteCharsSimple(char[] chars, int len = 0)
 {
     Contract.Requires(TextEncoding.GetByteCount(chars) <= WriteSpaceLeft);
     WritePosition += TextEncoding.GetBytes(chars, 0, len == 0 ? chars.Length : len, _buf, WritePosition);
 }
示例#6
0
 internal void WriteStringSimple(string s, int len = 0)
 {
     Contract.Requires(TextEncoding.GetByteCount(s) <= WriteSpaceLeft);
     WritePosition += TextEncoding.GetBytes(s, 0, len == 0 ? s.Length : len, _buf, WritePosition);
 }
示例#7
0
 /// <summary>
 /// Gets the length of the body of this message.
 /// </summary>
 /// <returns>The length of the body of this message.</returns>
 protected override int GetBodyLength()
 {
     return(TextEncoding.GetByteCount(m_username));
 }
示例#8
0
 public void WriteString(string s, int len = 0)
 {
     Debug.Assert(TextEncoding.GetByteCount(s) <= WriteSpaceLeft);
     WritePosition += TextEncoding.GetBytes(s, 0, len == 0 ? s.Length : len, Buffer, WritePosition);
 }
示例#9
0
 internal void WriteChars(char[] chars, int offset, int len)
 {
     Debug.Assert(TextEncoding.GetByteCount(chars) <= WriteSpaceLeft);
     _writePosition += TextEncoding.GetBytes(chars, offset, len == 0 ? chars.Length : len, _buf, _writePosition);
 }
示例#10
0
 internal void WriteString(string s, int len = 0)
 {
     Debug.Assert(TextEncoding.GetByteCount(s) <= WriteSpaceLeft);
     _writePosition += TextEncoding.GetBytes(s, 0, len == 0 ? s.Length : len, _buf, _writePosition);
 }
示例#11
0
 public override int GetOutputSize(string item)
 {
     return(TextEncoding.GetByteCount(item));
 }