コード例 #1
0
        internal static AuthenticationMD5PasswordMessage Load(NpgsqlReadBuffer buf)
        {
            var salt = new byte[4];

            buf.ReadBytes(salt, 0, 4);
            return(new AuthenticationMD5PasswordMessage(salt));
        }
コード例 #2
0
        internal static AuthenticationGSSContinueMessage Load(NpgsqlReadBuffer buf, int len)
        {
            len -= 4;   // The AuthRequestType code
            var authenticationData = new byte[len];

            buf.ReadBytes(authenticationData, 0, len);
            return(new AuthenticationGSSContinueMessage(authenticationData));
        }
コード例 #3
0
        /// <inheritdoc />
        public override PhysicalAddress Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription = null)
        {
            Debug.Assert(len == 6 || len == 8);

            var bytes = new byte[len];

            buf.ReadBytes(bytes, 0, len);
            return(new PhysicalAddress(bytes));
        }
コード例 #4
0
        public override Guid Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
        {
            var a = buf.ReadInt32();
            var b = buf.ReadInt16();
            var c = buf.ReadInt16();
            var d = new byte[8];

            buf.ReadBytes(d, 0, 8);
            return(new Guid(a, b, c, d));
        }
コード例 #5
0
        /// <inheritdoc />
        public override async ValueTask <byte[]> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
        {
            var bytes = new byte[len];
            var pos   = 0;

            while (true)
            {
                var toRead = Math.Min(len - pos, buf.ReadBytesLeft);
                buf.ReadBytes(bytes, pos, toRead);
                pos += toRead;
                if (pos == len)
                {
                    break;
                }
                await buf.ReadMore(async);
            }
            return(bytes);
        }
コード例 #6
0
            static async ValueTask <string> ReadLong(NpgsqlReadBuffer buf, int byteLen, bool async)
            {
                if (byteLen <= buf.Size)
                {
                    // The string's byte representation can fit in our read buffer, read it.
                    while (buf.ReadBytesLeft < byteLen)
                    {
                        await buf.ReadMore(async);
                    }
                    return(buf.ReadString(byteLen));
                }

                // Bad case: the string's byte representation doesn't fit in our buffer.
                // This is rare - will only happen in CommandBehavior.Sequential mode (otherwise the
                // entire row is in memory). Tweaking the buffer length via the connection string can
                // help avoid this.

                // Allocate a temporary byte buffer to hold the entire string and read it in chunks.
                var tempBuf = new byte[byteLen];
                var pos     = 0;

                while (true)
                {
                    var len = Math.Min(buf.ReadBytesLeft, byteLen - pos);
                    buf.ReadBytes(tempBuf, pos, len);
                    pos += len;
                    if (pos < byteLen)
                    {
                        await buf.ReadMore(async);

                        continue;
                    }
                    break;
                }
                return(buf.TextEncoding.GetString(tempBuf));
            }
コード例 #7
0
 internal AuthenticationSASLFinalMessage(NpgsqlReadBuffer buf, int len)
 {
     Payload = new byte[len];
     buf.ReadBytes(Payload, 0, len);
 }