Exemple #1
0
 public override void Deserialize(SectionFlag desiredSections)
 {
     if (!this.deserialized)
     {
         BufferListStream  stream = (BufferListStream)this.bufferStream.Clone();
         AmqpMessageReader reader = new AmqpMessageReader(stream);
         reader.ReadMessage(this, desiredSections);
         stream.Dispose();
         this.deserialized = true;
     }
 }
Exemple #2
0
            static void ReadDataSection(AmqpMessageReader reader, AmqpMessage message)
            {
                FormatCode formatCode = reader.ReadFormatCode();

                Fx.Assert(formatCode == FormatCode.Binary8 || formatCode == FormatCode.Binary32, "Invalid binary format code");
                bool smallEncoding         = formatCode == FormatCode.Binary8;
                int  count                 = reader.ReadInt(smallEncoding);
                ArraySegment <byte> buffer = reader.ReadBytes(count);

                AmqpMessage.EnsureInitialized <List <Data> >(ref reader.dataList);
                reader.dataList.Add(new Data()
                {
                    Value = buffer
                });

                reader.AddBodyBuffer(buffer);
            }
Exemple #3
0
            static T ReadMapSection <T>(AmqpMessageReader reader) where T : DescribedMap, new()
            {
                T          section    = new T();
                FormatCode formatCode = reader.ReadFormatCode();

                Fx.Assert(formatCode == FormatCode.Map8 || formatCode == FormatCode.Map32, "Invalid map format code");
                bool smallEncoding = formatCode == FormatCode.Map8;
                int  size          = reader.ReadInt(smallEncoding);
                int  count         = reader.ReadInt(smallEncoding);

                if (count > 0)
                {
                    ArraySegment <byte> bytes = reader.ReadBytes(size - (smallEncoding ? FixedWidth.UByte : FixedWidth.UInt));
                    section.DecodeValue(ByteBuffer.Wrap(bytes), size, count);
                }

                return(section);
            }
Exemple #4
0
            static T ReadListSection <T>(AmqpMessageReader reader, bool isBodySection = false) where T : DescribedList, new()
            {
                T          section    = new T();
                long       position   = reader.stream.Position;
                FormatCode formatCode = reader.ReadFormatCode();

                Fx.Assert(formatCode == FormatCode.List8 || formatCode == FormatCode.List0 || formatCode == FormatCode.List32, "Invalid list format code");
                if (formatCode == FormatCode.List0)
                {
                    return(section);
                }

                bool smallEncoding = formatCode == FormatCode.List8;
                int  size          = reader.ReadInt(smallEncoding);
                int  count         = reader.ReadInt(smallEncoding);

                if (count == 0)
                {
                    return(section);
                }

                long position2 = reader.stream.Position;

                ArraySegment <byte> bytes = reader.ReadBytes(size - (smallEncoding ? FixedWidth.UByte : FixedWidth.UInt));
                long position3            = reader.stream.Position;

                section.DecodeValue(ByteBuffer.Wrap(bytes), size, count);

                // Check if we are decoding the AMQP value body
                if (isBodySection)
                {
                    reader.stream.Position = position;
                    ArraySegment <byte> segment = reader.stream.ReadBytes((int)(position2 - position));
                    reader.stream.Position = position3;

                    reader.AddBodyBuffer(segment);
                    reader.AddBodyBuffer(bytes);
                }

                return(section);
            }
Exemple #5
0
            static void ReadAmqpValueSection(AmqpMessageReader reader, AmqpMessage message)
            {
                ArraySegment <byte> buffer     = reader.ReadBytes(int.MaxValue);
                ByteBuffer          byteBuffer = ByteBuffer.Wrap(buffer);
                object value = AmqpCodec.DecodeObject(byteBuffer);

                reader.amqpValue = new AmqpValue()
                {
                    Value = value
                };

                reader.AddBodyBuffer(buffer);

                // we didn't know the size and the buffer may include the footer
                if (byteBuffer.Length > 0)
                {
                    Footer footer = new Footer();
                    footer.Decode(byteBuffer);
                    message.Footer = footer;
                }
            }
Exemple #6
0
            protected override void OnInitialize()
            {
                // mask off immutable sections except footer
                this.properties            = null;
                this.applicationProperties = null;
                this.footer = null;

                BufferListStream stream = this.messageStream as BufferListStream;

                if (stream != null && !this.ownStream)
                {
                    stream = (BufferListStream)stream.Clone();
                }
                else
                {
                    int length = 0;
                    ArraySegment <byte>[] buffers = AmqpMessage.ReadStream(this.messageStream, 512, out length);
                    stream = new BufferListStream(buffers);
                }

                AmqpMessageReader reader       = new AmqpMessageReader(stream);
                AmqpMessage       emptyMessage = AmqpMessage.Create();

                reader.ReadMessage(emptyMessage, SectionFlag.Header | SectionFlag.DeliveryAnnotations | SectionFlag.MessageAnnotations);
                this.UpdateHeader(emptyMessage.header);
                this.UpdateDeliveryAnnotations(emptyMessage.deliveryAnnotations);
                this.UpdateMessageAnnotations(emptyMessage.messageAnnotations);

                // read out the remaining buffers
                bool unused = false;

                this.buffers = stream.ReadBuffers(int.MaxValue, true, out unused);

                stream.Dispose();
                if (this.ownStream)
                {
                    this.messageStream.Dispose();
                }
            }
Exemple #7
0
 static void ReadFooterSection(AmqpMessageReader reader, AmqpMessage message)
 {
     message.Footer = ReadMapSection <Footer>(reader);
 }
Exemple #8
0
 static void ReadAmqpSequenceSection(AmqpMessageReader reader, AmqpMessage message)
 {
     AmqpMessage.EnsureInitialized <List <AmqpSequence> >(ref reader.sequenceList);
     reader.sequenceList.Add(ReadListSection <AmqpSequence>(reader, true));
 }
Exemple #9
0
 static void ReadApplicationPropertiesSection(AmqpMessageReader reader, AmqpMessage message)
 {
     message.ApplicationProperties = ReadMapSection <ApplicationProperties>(reader);
 }
Exemple #10
0
 static void ReadPropertiesSection(AmqpMessageReader reader, AmqpMessage message)
 {
     message.Properties = ReadListSection <Properties>(reader);
 }
Exemple #11
0
 static void ReadMessageAnnotationsSection(AmqpMessageReader reader, AmqpMessage message)
 {
     message.MessageAnnotations = ReadMapSection <MessageAnnotations>(reader);
 }
Exemple #12
0
 static void ReadDeliveryAnnotationsSection(AmqpMessageReader reader, AmqpMessage message)
 {
     message.DeliveryAnnotations = ReadMapSection <DeliveryAnnotations>(reader);
 }
Exemple #13
0
 static void ReadHeaderSection(AmqpMessageReader reader, AmqpMessage message)
 {
     message.Header = ReadListSection <Header>(reader);
 }