Пример #1
0
        public static object DecodeObject(ByteBuffer buffer)
        {
            FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer);

            if (formatCode == 64)
            {
                return(null);
            }
            if (formatCode != 0)
            {
                return(AmqpEncoding.DecodeObject(buffer, formatCode));
            }
            object obj = AmqpCodec.DecodeObject(buffer);
            Func <AmqpDescribed> func = null;

            if (obj is AmqpSymbol)
            {
                Dictionary <string, Func <AmqpDescribed> > strs = AmqpCodec.knownTypesByName;
                AmqpSymbol amqpSymbol = (AmqpSymbol)obj;
                strs.TryGetValue(amqpSymbol.Value, out func);
            }
            else if (obj is ulong)
            {
                AmqpCodec.knownTypesByCode.TryGetValue((ulong)obj, out func);
            }
            if (func == null)
            {
                return(new DescribedType(obj, AmqpCodec.DecodeObject(buffer)));
            }
            AmqpDescribed amqpDescribed = func();

            amqpDescribed.DecodeValue(buffer);
            return(amqpDescribed);
        }
Пример #2
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;
                }
            }
Пример #3
0
        public static object DecodeObject(ByteBuffer buffer)
        {
            FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer);

            if (formatCode == FormatCode.Null)
            {
                return(null);
            }
            else if (formatCode == FormatCode.Described)
            {
                object descriptor = AmqpCodec.DecodeObject(buffer);
                Func <AmqpDescribed> knownTypeCtor = null;
                if (descriptor is AmqpSymbol)
                {
                    knownTypesByName.TryGetValue(((AmqpSymbol)descriptor).Value, out knownTypeCtor);
                }
                else if (descriptor is ulong)
                {
                    knownTypesByCode.TryGetValue((ulong)descriptor, out knownTypeCtor);
                }

                if (knownTypeCtor != null)
                {
                    AmqpDescribed amqpDescribed = knownTypeCtor();
                    amqpDescribed.DecodeValue(buffer);
                    return(amqpDescribed);
                }
                else
                {
                    object value = AmqpCodec.DecodeObject(buffer);
                    return(new DescribedType(descriptor, value));
                }
            }
            else
            {
                return(AmqpEncoding.DecodeObject(buffer, formatCode));
            }
        }