Beispiel #1
0
    internal Task WriteClose(StatementOrPortal type, string name, bool async, CancellationToken cancellationToken = default)
    {
        var len = sizeof(byte) +               // Message code
                  sizeof(int) +                // Length
                  sizeof(byte) +               // Statement or portal
                  name.Length + sizeof(byte);  // Statement or portal name plus null terminator

        if (WriteBuffer.WriteSpaceLeft < 10)
        {
            return(FlushAndWrite(len, type, name, async, cancellationToken));
        }

        Write(len, type, name);
        return(Task.CompletedTask);

        async Task FlushAndWrite(int len, StatementOrPortal type, string name, bool async, CancellationToken cancellationToken)
        {
            await Flush(async, cancellationToken);

            Debug.Assert(len <= WriteBuffer.WriteSpaceLeft, $"Message of type {GetType().Name} has length {len} which is bigger than the buffer ({WriteBuffer.WriteSpaceLeft})");
            Write(len, type, name);
        }

        void Write(int len, StatementOrPortal type, string name)
        {
            WriteBuffer.WriteByte(FrontendMessageCode.Close);
            WriteBuffer.WriteInt32(len - 1);
            WriteBuffer.WriteByte((byte)type);
            WriteBuffer.WriteNullTerminatedString(name);
        }
    }
Beispiel #2
0
        internal Task WriteDescribe(StatementOrPortal statementOrPortal, string name, bool async)
        {
            Debug.Assert(name.All(c => c < 128));

            var len = sizeof(byte) +       // Message code
                      sizeof(int) +        // Length
                      sizeof(byte) +       // Statement or portal
                      (name.Length + 1);   // Statement/portal name

            if (WriteBuffer.WriteSpaceLeft < len)
            {
                return(FlushAndWrite(len, statementOrPortal, name, async));
            }

            Write(len, statementOrPortal, name);
            return(Task.CompletedTask);

            async Task FlushAndWrite(int len, StatementOrPortal statementOrPortal, string name, bool async)
            {
                await Flush(async);

                Debug.Assert(len <= WriteBuffer.WriteSpaceLeft, $"Message of type {GetType().Name} has length {len} which is bigger than the buffer ({WriteBuffer.WriteSpaceLeft})");
                Write(len, statementOrPortal, name);
            }

            void Write(int len, StatementOrPortal statementOrPortal, string name)
            {
                WriteBuffer.WriteByte(FrontendMessageCode.Describe);
                WriteBuffer.WriteInt32(len - 1);
                WriteBuffer.WriteByte((byte)statementOrPortal);
                WriteBuffer.WriteNullTerminatedString(name);
            }
        }
Beispiel #3
0
 internal CloseMessage(StatementOrPortal type, string name="")
 {
     StatementOrPortal = type;
     Name = name;
 }
Beispiel #4
0
 internal CloseMessage(StatementOrPortal type, string name = "")
 {
     StatementOrPortal = type;
     Name = name;
 }
 internal DescribeMessage Populate(StatementOrPortal type, string name = null)
 {
     StatementOrPortal = type;
     Name = name ?? "";
     return this;
 }
Beispiel #6
0
 internal DescribeMessage Populate(StatementOrPortal type, string name = null)
 {
     StatementOrPortal = type;
     Name = name ?? "";
     return(this);
 }
Beispiel #7
0
 internal CloseMessage Populate(StatementOrPortal type, string name = "")
 {
     StatementOrPortal = type;
     Name = name;
     return(this);
 }