Example #1
0
        public async Task Send_StartOk(string connectionName, string userName, string password, string mechanism = "PLAIN", string locale = "en_US")
        {
            var buffer = await socket.GetWriteBuffer();

            try
            {
                WritePayload();
                await buffer.FlushAsync();
            }
            finally
            {
                socket.ReleaseWriteBuffer();
            }

            void WritePayload()
            {
                var writer = new CustomBufferWriter <PipeWriter>(buffer);

                var payloadSizeHeader = writer.WriteFrameHeader(FrameType.Method, connectionChannelNumber);

                writer.Write(Method.Connection.StartOk);

                var clientProperties = new Dictionary <string, object>
                {
                    { "product", "Angora" },
                    { "capabilities", capabilities },
                    { "connection_name", connectionName }
                };

                writer.WriteTable(clientProperties);
                writer.WriteShortString(mechanism);
                writer.WriteLongString($"\0{userName}\0{password}"); //response
                writer.WriteShortString(locale);

                writer.Commit();
                BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, ((uint)writer.BytesCommitted - FrameHeaderSize));

                writer.Write(FrameEnd);

                writer.Commit();
            }
        }