Beispiel #1
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);
            }
Beispiel #2
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);
            }
Beispiel #3
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);
            }
Beispiel #4
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;
                }
            }