Example #1
0
        public void WriteMessage(QueueInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            writer.WriteOctet(1);
            writer.WriteShortInt(ChannelId);
            var reseved    = writer.Reserve(4);
            var checkpoint = writer.Written;

            FrameWriter.WriteMethodFrame(50, 10, ref writer);
            writer.WriteShortInt(0); //reserved-1
            writer.WriteShortStr(message.Name);
            writer.WriteBit(message.Passive);
            writer.WriteBit(message.Durable);
            writer.WriteBit(message.Exclusive);
            writer.WriteBit(message.AutoDelete);
            writer.WriteBit(message.NoWait);
            writer.WriteTable(message.Arguments);
            var payloadSize = writer.Written - checkpoint;

            writer.WriteOctet(Constants.FrameEnd);

            Span <byte> span = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(span, payloadSize);
            reseved.Write(span);

            writer.Commit();
        }
        public void WriteMessage(QueueDelete message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            writer.WriteOctet(RabbitMQConstants.FrameMethod);
            writer.WriteShortInt(_channelId);
            var reserved   = writer.Reserve(4);
            var checkpoint = writer.Written;

            FrameWriter.WriteMethodFrame(50, 40, ref writer);
            writer.WriteShortInt(0); //reserved-1
            writer.WriteShortStr(message.Name);
            writer.WriteBit(message.IfUnused);
            writer.WriteBit(message.IfEmpty);
            writer.WriteBit(message.NoWait);
            writer.BitFlush();
            var payloadSize = writer.Written - checkpoint;

            writer.WriteOctet(RabbitMQConstants.FrameEnd);

            Span <byte> span = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(span, payloadSize);
            reserved.Write(span);

            writer.Commit();
        }
        internal void WriteMessage(ref ContentHeader message, ref ValueWriter writer)
        {
            _bitCount = 0;
            _flagWord = 0;
            writer.WriteOctet(RabbitMQConstants.FrameHeader);
            writer.WriteShortInt(_channelId);
            var reserved   = writer.Reserve(4);
            var checkpoint = writer.Written;

            writer.WriteShortInt(message.ClassId);
            writer.WriteShortInt(message.Weight);
            writer.WriteLongLong(message.BodySize);

            WriteBitFlagsAndContinuation(ref message.Properties, ref writer);


            var payloadSize = writer.Written - checkpoint;

            writer.WriteOctet(RabbitMQConstants.FrameEnd);

            Span <byte> span = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(span, payloadSize);
            reserved.Write(span);

            writer.Commit();
        }
Example #4
0
        public void WriteMessage(ContentHeader message, IBufferWriter <byte> output)
        {
            m_bitCount = 0;
            m_flagWord = 0;
            ValueWriter writer = new ValueWriter(output);

            writer.WriteOctet(Constants.FrameHeader);
            writer.WriteShortInt(_channelId);
            var reserved   = writer.Reserve(4);
            var checkpoint = writer.Written;

            writer.WriteShortInt(message.ClassId);
            writer.WriteShortInt(message.Weight);
            writer.WriteLongLong(message.BodySize);

            WriteBitFlagsAndContinuation(ref message, ref writer);


            var payloadSize = writer.Written - checkpoint;

            writer.WriteOctet(Constants.FrameEnd);

            Span <byte> span = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(span, payloadSize);
            reserved.Write(span);

            writer.Commit();
        }
Example #5
0
        public void WriteMessage(QueueBind message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            writer.WriteOctet(1);
            writer.WriteShortInt(_channelId);
            var reserved   = writer.Reserve(4);
            var checkpoint = writer.Written;

            FrameWriter.WriteMethodFrame(50, 20, ref writer);
            writer.WriteShortInt(0); //reserved-1
            writer.WriteShortStr(message.QueueName);
            writer.WriteShortStr(message.ExchangeName);
            writer.WriteShortStr(message.RoutingKey);
            writer.WriteBit(message.NoWait);
            writer.WriteTable(message.Arguments);
            var payloadSize = writer.Written - checkpoint;

            writer.WriteOctet(RabbitMQConstants.FrameEnd);

            Span <byte> span = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(span, payloadSize);
            reserved.Write(span);

            writer.Commit();
        }
        public void WriteMessage(ExchangeDeclare message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            writer.WriteOctet(1);
            writer.WriteShortInt(_channelId);
            var reserved   = writer.Reserve(4);
            var checkpoint = writer.Written;

            FrameWriter.WriteMethodFrame(40, 10, ref writer);
            writer.WriteShortInt(0); //reseved-1
            writer.WriteShortStr(message.Name);
            writer.WriteShortStr(message.Type);

            writer.WriteBit(message.Passive);
            writer.WriteBit(message.Durable);
            writer.WriteBit(message.AutoDelete);
            writer.WriteBit(message.Internal);
            writer.WriteBit(message.NoWait);
            writer.WriteTable(message.Arguments);
            var size = writer.Written - checkpoint;

            writer.WriteOctet(RabbitMQConstants.FrameEnd);

            Span <byte> sizeSpan = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(sizeSpan, size);
            reserved.Write(sizeSpan);

            writer.Commit();
        }
Example #7
0
        public void WriteMessage(ushort message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(1, message, 5, ref writer);
            FrameWriter.WriteMethodFrame(20, 10, ref writer);
            writer.WriteOctet(0);
            writer.WriteOctet(206);
            writer.Commit();
        }
 internal void WriteMessage(ReadOnlyMemory <byte> message, ref ValueWriter writer)
 {
     FrameWriter.WriteFrameHeader(RabbitMQConstants.FrameBody, _channelId, message.Length, ref writer);
     writer.WriteBytes(message.Span);
     writer.WriteOctet(RabbitMQConstants.FrameEnd);
     writer.Commit();
 }
Example #9
0
        public void WriteMessage(byte[] message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(Constants.FrameBody, _channelId, message.Length, ref writer);
            writer.WriteBytes(message);
            writer.WriteOctet(Constants.FrameEnd);
            writer.Commit();
        }
Example #10
0
        public void WriteMessage(NoPaylodMethodInfo message, IBufferWriter <byte> output)
        {
            var writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(message.FrameType, message.Channel, 4, ref writer);
            FrameWriter.WriteMethodFrame(message.ClassId, message.MethodId, ref writer);
            writer.WriteOctet(RabbitMQConstants.FrameEnd);
            writer.Commit();
        }
Example #11
0
        public void WriteMessage(RejectInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(Constants.FrameMethod, _channel, 13, ref writer);
            FrameWriter.WriteMethodFrame(60, 90, ref writer);
            writer.WriteLongLong(message.DeliveryTag);
            writer.WriteBit(message.Requeue);
            writer.WriteOctet(Constants.FrameEnd);
        }
Example #12
0
        public void WriteMessage(PublishAllInfo message, IBufferWriter <byte> output)
        {
            var writer = new ValueWriter(output);

            var framePayloadSize = 9 + message.Info.ExchangeName.Length + message.Info.RoutingKey.Length;

            FrameWriter.WriteFrameHeader(RabbitMQConstants.FrameMethod, message.ChannelId, framePayloadSize, ref writer);
            FrameWriter.WriteMethodFrame(60, 40, ref writer);
            writer.WriteShortInt(0); //reserved-1
            writer.WriteShortStr(message.Info.ExchangeName);
            writer.WriteShortStr(message.Info.RoutingKey);
            writer.WriteBit(message.Info.Mandatory);
            writer.WriteBit(message.Info.Immediate);
            writer.BitFlush();
            writer.WriteOctet(RabbitMQConstants.FrameEnd);

            _bitCount = 0;
            _flagWord = 0;
            writer.WriteOctet(RabbitMQConstants.FrameHeader);
            writer.WriteShortInt(message.ChannelId);
            var reserved   = writer.Reserve(4);
            var checkpoint = writer.Written;

            writer.WriteShortInt(message.Header.ClassId);
            writer.WriteShortInt(message.Header.Weight);
            writer.WriteLongLong(message.Header.BodySize);
            WriteBitFlagsAndContinuation(ref message.Header.Properties, ref writer);
            var payloadSize = writer.Written - checkpoint;

            writer.WriteOctet(RabbitMQConstants.FrameEnd);
            Span <byte> span = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(span, payloadSize);
            reserved.Write(span);

            FrameWriter.WriteFrameHeader(RabbitMQConstants.FrameBody, message.ChannelId, message.Body.Length, ref writer);
            writer.WriteBytes(message.Body.Span);
            writer.WriteOctet(RabbitMQConstants.FrameEnd);


            writer.Commit();
        }
        public void WriteMessage(AckInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(Constants.FrameMethod, _channelId, 13, ref writer);
            FrameWriter.WriteMethodFrame(60, 80, ref writer);
            writer.WriteLongLong(message.DeliveryTag);
            writer.WriteBit(message.Multiple);
            writer.BitFlush();
            writer.WriteOctet(Constants.FrameEnd);
            writer.Commit();
        }
Example #14
0
        public void WriteMessage(RabbitMQMainInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(1, 0, 12, ref writer);
            FrameWriter.WriteMethodFrame(10, 31, ref writer);
            writer.WriteShortInt(message.ChannelMax);
            writer.WriteLong(message.FrameMax);
            writer.WriteShortInt(message.Heartbeat);
            writer.WriteOctet(206);
            writer.Commit();
        }
        public void WriteMessage(string message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            writer.WriteOctet(1);
            writer.WriteShortInt(0);
            var reserved   = writer.Reserve(4);
            var checkpoint = writer.Written;

            FrameWriter.WriteMethodFrame(10, 40, ref writer);
            writer.WriteShortStr(message);
            writer.WriteOctet(0);
            writer.WriteOctet(0);
            var paylodaSize = writer.Written - checkpoint;

            writer.WriteOctet(206);
            Span <byte> bytes = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(bytes, paylodaSize);
            reserved.Write(bytes);
            writer.Commit();
        }
        public void WriteMessage(ReadOnlyMemory <byte> message, IBufferWriter <byte> output)
        {
            if (message.IsEmpty)
            {
                return;
            }
            var writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(RabbitMQConstants.FrameBody, _channelId, message.Length, ref writer);
            writer.WriteBytes(message.Span);
            writer.WriteOctet(RabbitMQConstants.FrameEnd);
            writer.Commit();
        }
        public void WriteMessage(QoSInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            FrameWriter.WriteFrameHeader(1, _channel, 11, ref writer);
            FrameWriter.WriteMethodFrame(60, 10, ref writer);
            writer.WriteLong(message.PrefetchSize);
            writer.WriteShortInt(message.PrefetchCount);
            writer.WriteBool(message.Global);
            writer.WriteOctet(RabbitMQConstants.FrameEnd);

            writer.Commit();
        }
        public void WriteMessage(ConsumeCancelInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            writer.WriteOctet(1);
            writer.WriteShortInt(_channelId);
            var reserved   = writer.Reserve(4);
            var checkpoint = writer.Written;

            FrameWriter.WriteMethodFrame(60, 30, ref writer);
            writer.WriteShortStr(message.ConsumerTag);
            writer.WriteBool(message.NoWait);
            var payloadSize = writer.Written - checkpoint;

            writer.WriteOctet(RabbitMQConstants.FrameEnd);

            Span <byte> sizeSpan = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(sizeSpan, 18);
            reserved.Write(sizeSpan);

            writer.Commit();
        }
Example #19
0
        public void WriteMessage(CloseInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer = new ValueWriter(output);

            writer.WriteOctet(1);
            writer.WriteShortInt(message.ChannelId);
            var reserved   = writer.Reserve(4);
            var checkpoint = writer.Written;

            FrameWriter.WriteMethodFrame(20, 40, ref writer);
            writer.WriteShortInt(message.ReplyCode);
            writer.WriteShortStr(message.ReplyText);
            writer.WriteShortInt(message.FailedClassId);
            writer.WriteShortInt(message.FailedMethodId);
            var size = writer.Written - checkpoint;

            writer.WriteOctet(206);
            Span <byte> sizeSpan = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(sizeSpan, size);
            reserved.Write(sizeSpan);
            writer.Commit();
        }
        public void WriteMessage(ClientConf message, IBufferWriter <byte> output)
        {
            var writer = new ValueWriter(output);

            writer.WriteOctet(1);
            writer.WriteShortInt(0);
            var reserved   = writer.Reserve(4);
            var checkpoint = writer.Written;

            FrameWriter.WriteMethodFrame(10, 11, ref writer);
            writer.WriteTable(message.Properties);
            writer.WriteShortStr(message.Mechanism);
            writer.WriteLongStr($"\0{_info.User}\0{_info.Password}");
            writer.WriteShortStr(message.Locale);
            var paylodaSize = writer.Written - checkpoint;

            writer.WriteOctet(206);

            Span <byte> bytes = stackalloc byte[4];

            BinaryPrimitives.WriteInt32BigEndian(bytes, paylodaSize);
            reserved.Write(bytes);
            writer.Commit();
        }
        internal void WriteMessage(ref BasicPublishInfo message, ref ValueWriter writer)
        {
            var payloadSize = 9 + message.ExchangeName.Length + message.RoutingKey.Length;

            FrameWriter.WriteFrameHeader(RabbitMQConstants.FrameMethod, _channelid, payloadSize, ref writer);
            //var checkpoint = writer.Written;
            FrameWriter.WriteMethodFrame(60, 40, ref writer);
            writer.WriteShortInt(0); //reserved-1
            writer.WriteShortStr(message.ExchangeName);
            writer.WriteShortStr(message.RoutingKey);
            writer.WriteBit(message.Mandatory);
            writer.WriteBit(message.Immediate);
            writer.BitFlush();
            //var size = writer.Written - checkpoint;
            writer.WriteOctet(RabbitMQConstants.FrameEnd);
            writer.Commit();
        }
Example #22
0
        public void WriteMessage(BasicPublishInfo message, IBufferWriter <byte> output)
        {
            ValueWriter writer      = new ValueWriter(output);
            var         payloadSize = 9 + message.ExchangeName.Length + message.RoutingKey.Length;

            FrameWriter.WriteFrameHeader(Constants.FrameMethod, _channelid, payloadSize, ref writer);
            //var checkpoint = writer.Written;
            FrameWriter.WriteMethodFrame(60, 40, ref writer);
            writer.WriteShortInt(0); //reserved-1
            writer.WriteShortStr(message.ExchangeName);
            writer.WriteShortStr(message.RoutingKey);
            writer.WriteBit(message.Mandatory);
            writer.WriteBit(message.Immediate);
            writer.BitFlush();
            //var size = writer.Written - checkpoint;
            writer.WriteOctet(Constants.FrameEnd);
            writer.Commit();
        }
        private void WriteBitFlagsAndContinuation(ref ContentHeaderProperties properties, ref ValueWriter writer)
        {
            WritePresence(properties.ContentType != null);
            WritePresence(properties.ContentEncoding != null);
            WritePresence(properties.Headers != null);
            WritePresence(properties.DeliveryMode != 0);
            WritePresence(properties.Priority != 0);
            WritePresence(properties.CorrelationId != null);
            WritePresence(properties.ReplyTo != null);
            WritePresence(properties.Expiration != null);
            WritePresence(properties.MessageId != null);
            WritePresence(properties.Timestamp != 0);
            WritePresence(properties.Type != null);
            WritePresence(properties.UserId != null);
            WritePresence(properties.AppId != null);
            WritePresence(properties.ClusterId != null);
            writer.WriteShortInt(_flagWord);
            if (properties.ContentType != null)
            {
                writer.WriteShortStr(properties.ContentType);
            }

            if (properties.ContentEncoding != null)
            {
                writer.WriteShortStr(properties.ContentEncoding);
            }

            if (properties.Headers != null)
            {
                writer.WriteTable(properties.Headers);
            }

            if (properties.DeliveryMode != 0)
            {
                writer.WriteOctet(properties.DeliveryMode);
            }

            if (properties.Priority != 0)
            {
                writer.WriteOctet(properties.Priority);
            }

            if (properties.CorrelationId != null)
            {
                writer.WriteShortStr(properties.CorrelationId);
            }

            if (properties.ReplyTo != null)
            {
                writer.WriteShortStr(properties.ReplyTo);
            }

            if (properties.Expiration != null)
            {
                writer.WriteShortStr(properties.Expiration);
            }

            if (properties.MessageId != null)
            {
                writer.WriteShortStr(properties.MessageId);
            }

            if (properties.Timestamp != 0)
            {
                writer.WriteLongLong(properties.Timestamp);
            }

            if (properties.Type != null)
            {
                writer.WriteShortStr(properties.Type);
            }

            if (properties.UserId != null)
            {
                writer.WriteShortStr(properties.UserId);
            }

            if (properties.AppId != null)
            {
                writer.WriteShortStr(properties.AppId);
            }

            if (properties.ClusterId != null)
            {
                writer.WriteShortStr(properties.ClusterId);
            }
        }
Example #24
0
 private void WriteBitFlagsAndContinuation(ref ContentHeader message, ref ValueWriter writer)
 {
     if (message.ContentType != null)
     {
         WritePresence(true);
     }
     if (message.ContentEncoding != null)
     {
         WritePresence(true);
     }
     if (message.Headers != null)
     {
         WritePresence(true);
     }
     if (message.DeliveryMode != 0)
     {
         WritePresence(true);
     }
     if (message.Priority != 0)
     {
         WritePresence(true);
     }
     if (message.CorrelationId != null)
     {
         WritePresence(true);
     }
     if (message.ReplyTo != null)
     {
         WritePresence(true);
     }
     if (message.Expiration != null)
     {
         WritePresence(true);
     }
     if (message.MessageId != null)
     {
         WritePresence(true);
     }
     if (message.Timestamp != 0)
     {
         WritePresence(true);
     }
     if (message.Type != null)
     {
         WritePresence(true);
     }
     if (message.UserId != null)
     {
         WritePresence(true);
     }
     if (message.AppId != null)
     {
         WritePresence(true);
     }
     if (message.ClusterId != null)
     {
         WritePresence(true);
     }
     writer.WriteShortInt(m_flagWord);
     if (message.ContentType != null)
     {
         writer.WriteShortStr(message.ContentType);
     }
     if (message.ContentEncoding != null)
     {
         writer.WriteShortStr(message.ContentEncoding);
     }
     if (message.Headers != null)
     {
         writer.WriteTable(message.Headers);
     }
     if (message.DeliveryMode != 0)
     {
         writer.WriteOctet(message.DeliveryMode);
     }
     if (message.Priority != 0)
     {
         writer.WriteOctet(message.Priority);
     }
     if (message.CorrelationId != null)
     {
         writer.WriteShortStr(message.CorrelationId);
     }
     if (message.ReplyTo != null)
     {
         writer.WriteShortStr(message.ReplyTo);
     }
     if (message.Expiration != null)
     {
         writer.WriteShortStr(message.Expiration);
     }
     if (message.MessageId != null)
     {
         writer.WriteShortStr(message.MessageId);
     }
     if (message.Timestamp != 0)
     {
         writer.WriteLongLong(message.Timestamp);
     }
     if (message.Type != null)
     {
         writer.WriteShortStr(message.Type);
     }
     if (message.UserId != null)
     {
         writer.WriteShortStr(message.UserId);
     }
     if (message.AppId != null)
     {
         writer.WriteShortStr(message.AppId);
     }
     if (message.ClusterId != null)
     {
         writer.WriteShortStr(message.ClusterId);
     }
 }