Пример #1
0
 public Section(SectionFlag flag, int offset, int length, AmqpDescribed value)
 {
     Flag   = flag;
     Offset = offset;
     Length = length;
     Value  = value;
 }
Пример #2
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);
        }
Пример #3
0
 internal static void EncodeSection(ByteBuffer buffer, AmqpDescribed section)
 {
     if (section != null)
     {
         section.Offset = buffer.WritePos;
         section.Encode(buffer);
         section.Length = buffer.WritePos - section.Offset;
     }
 }
Пример #4
0
        public static AmqpDescribed DecodeAmqpDescribed(ByteBuffer buffer, Dictionary <string, Func <AmqpDescribed> > byName, Dictionary <ulong, Func <AmqpDescribed> > byCode)
        {
            AmqpDescribed amqpDescribed = AmqpCodec.CreateAmqpDescribed(buffer, byName, byCode);

            if (amqpDescribed != null)
            {
                amqpDescribed.DecodeValue(buffer);
            }
            return(amqpDescribed);
        }
Пример #5
0
        /// <summary>
        /// Decodes an <see cref="AmqpDescribed"/> object from the buffer.
        /// </summary>
        /// <param name="buffer">The input buffer.</param>
        /// <returns>An AmqpDescribed object.</returns>
        public static AmqpDescribed DecodeAmqpDescribed(ByteBuffer buffer)
        {
            AmqpDescribed value = CreateAmqpDescribed(buffer, knownTypesByName, knownTypesByCode);

            if (value != null)
            {
                value.DecodeValue(buffer);
            }

            return(value);
        }
Пример #6
0
        public static AmqpDescribed DecodeAmqpDescribed(
            ByteBuffer buffer,
            Dictionary <string, Func <AmqpDescribed> > byName,
            Dictionary <ulong, Func <AmqpDescribed> > byCode)
        {
            AmqpDescribed value = CreateAmqpDescribed(buffer, byName, byCode);

            if (value != null)
            {
                value.DecodeValue(buffer);
            }

            return(value);
        }
Пример #7
0
 static void WriteSection(ByteBuffer buffer, AmqpDescribed section, ByteBuffer source)
 {
     if (section != null)
     {
         if (source != null)
         {
             AmqpBitConverter.WriteBytes(buffer, source.Buffer, section.Offset, section.Length);
         }
         else
         {
             AmqpMessage.EncodeSection(buffer, section);
         }
     }
 }
Пример #8
0
        /// <summary>
        /// Decodes an AMQP object from the buffer and advances the buffer's position.
        /// </summary>
        /// <param name="buffer">The buffer to read.</param>
        /// <returns>An AMQP object.</returns>
        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));
            }
        }
Пример #9
0
        internal static AmqpDescribed CreateAmqpDescribed(
            ByteBuffer buffer,
            Dictionary <string, Func <AmqpDescribed> > byName,
            Dictionary <ulong, Func <AmqpDescribed> > byCode)
        {
            FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer);

            if (formatCode == FormatCode.Null)
            {
                return(null);
            }

            EncodingBase.VerifyFormatCode(formatCode, buffer.Offset, FormatCode.Described);

            Func <AmqpDescribed> knownTypeCtor = null;

            formatCode = AmqpEncoding.ReadFormatCode(buffer);
            if (formatCode == FormatCode.Symbol8 || formatCode == FormatCode.Symbol32)
            {
                AmqpSymbol name = SymbolEncoding.Decode(buffer, formatCode);
                byName.TryGetValue(name.Value, out knownTypeCtor);
            }
            else if (formatCode == FormatCode.ULong0 || formatCode == FormatCode.ULong || formatCode == FormatCode.SmallULong)
            {
                ulong code = ULongEncoding.Decode(buffer, formatCode).Value;
                byCode.TryGetValue(code, out knownTypeCtor);
            }

            if (knownTypeCtor == null)
            {
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
            }

            AmqpDescribed value = knownTypeCtor();

            return(value);
        }