Exemplo n.º 1
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();
        }
        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();
        }
Exemplo n.º 3
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);
        }
        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();
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
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);
     }
 }
        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);
            }
        }