Exemplo n.º 1
0
        public static string Decode(ByteBuffer buffer, Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode formatCode)
        {
            int num;

            System.Text.Encoding uTF8;
            if (formatCode == 0)
            {
                Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode formatCode1 = AmqpEncoding.ReadFormatCode(buffer);
                formatCode = formatCode1;
                if (formatCode1 == 64)
                {
                    return(null);
                }
            }
            if (formatCode != 161)
            {
                if (formatCode != 177)
                {
                    throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
                }
                num  = (int)AmqpBitConverter.ReadUInt(buffer);
                uTF8 = System.Text.Encoding.UTF8;
            }
            else
            {
                num  = AmqpBitConverter.ReadUByte(buffer);
                uTF8 = System.Text.Encoding.UTF8;
            }
            string str = uTF8.GetString(buffer.Buffer, buffer.Offset, num);

            buffer.Complete(num);
            return(str);
        }
Exemplo n.º 2
0
 public static void VerifyFormatCode(Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode formatCode, Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode expected, int offset)
 {
     if (formatCode != expected)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, offset));
     }
 }
Exemplo n.º 3
0
        public static AmqpDescribed CreateAmqpDescribed(ByteBuffer buffer, Dictionary <string, Func <AmqpDescribed> > byName, Dictionary <ulong, Func <AmqpDescribed> > byCode)
        {
            FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer);

            if (formatCode == 64)
            {
                return(null);
            }
            EncodingBase.VerifyFormatCode(formatCode, 0, buffer.Offset);
            Func <AmqpDescribed> func = null;

            formatCode = AmqpEncoding.ReadFormatCode(buffer);
            if (formatCode == 163 || formatCode == 179)
            {
                AmqpSymbol amqpSymbol = SymbolEncoding.Decode(buffer, formatCode);
                byName.TryGetValue(amqpSymbol.Value, out func);
            }
            else if (formatCode == 68 || formatCode == 128 || formatCode == 83)
            {
                ulong?nullable = ULongEncoding.Decode(buffer, formatCode);
                byCode.TryGetValue(nullable.Value, out func);
            }
            if (func == null)
            {
                throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
            }
            return(func());
        }
Exemplo n.º 4
0
        private static DescribedType Decode(ByteBuffer buffer, Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode formatCode)
        {
            if (formatCode != 0)
            {
                throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
            }
            object obj = AmqpEncoding.DecodeObject(buffer);

            return(new DescribedType(obj, AmqpEncoding.DecodeObject(buffer)));
        }
Exemplo n.º 5
0
        public static object DecodeObject(ByteBuffer buffer, FormatCode formatCode)
        {
            EncodingBase encodingBase;

            if (!AmqpEncoding.encodingsByCode.TryGetValue(formatCode, out encodingBase))
            {
                throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
            }
            return(encodingBase.DecodeObject(buffer, formatCode));
        }
Exemplo n.º 6
0
 protected override void Initialize(ByteBuffer buffer, FormatCode formatCode, out int size, out int count, out int encodeWidth, out SerializableType.CollectionType effectiveType)
 {
     if (formatCode != 209 && formatCode != 193)
     {
         throw new AmqpException(AmqpError.InvalidField, SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
     }
     encodeWidth = (formatCode == 193 ? 1 : 4);
     AmqpEncoding.ReadSizeAndCount(buffer, formatCode, 193, 209, out size, out count);
     effectiveType = this;
 }
Exemplo n.º 7
0
 public static void ReadCount(ByteBuffer buffer, FormatCode formatCode, FormatCode formatCode8, FormatCode formatCode32, out int count)
 {
     if (formatCode == formatCode8)
     {
         count = AmqpBitConverter.ReadUByte(buffer);
         return;
     }
     if (formatCode != formatCode32)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
     }
     count = (int)AmqpBitConverter.ReadUInt(buffer);
 }
Exemplo n.º 8
0
        public static void DecodeDescriptor(ByteBuffer buffer, out AmqpSymbol name, out ulong code)
        {
            name = new AmqpSymbol();
            code = (ulong)0;
            FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer);

            if (formatCode == 0)
            {
                formatCode = AmqpEncoding.ReadFormatCode(buffer);
            }
            if (formatCode == 163 || formatCode == 179)
            {
                name = SymbolEncoding.Decode(buffer, formatCode);
                return;
            }
            if (!(formatCode == 128) && !(formatCode == 68) && !(formatCode == 83))
            {
                throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
            }
            code = ULongEncoding.Decode(buffer, formatCode).Value;
        }
Exemplo n.º 9
0
 protected override void Initialize(ByteBuffer buffer, FormatCode formatCode, out int size, out int count, out int encodeWidth, out SerializableType.CollectionType effectiveType)
 {
     if (formatCode == 69)
     {
         int num  = 0;
         int num1 = num;
         encodeWidth = num;
         int num2 = num1;
         int num3 = num2;
         count         = num2;
         size          = num3;
         effectiveType = this;
         return;
     }
     if (formatCode != 208 && formatCode != 192)
     {
         throw new AmqpException(AmqpError.InvalidField, SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
     }
     encodeWidth = (formatCode == 192 ? 1 : 4);
     AmqpEncoding.ReadSizeAndCount(buffer, formatCode, 192, 208, out size, out count);
     effectiveType = this;
 }
Exemplo n.º 10
0
        private static decimal DecodeValue(ByteBuffer buffer, Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode formatCode)
        {
            decimal num  = new decimal(0);
            byte    num1 = formatCode;

            if (num1 == 116)
            {
                num = DecimalEncoding.DecodeDecimal32(buffer);
            }
            else if (num1 == 132)
            {
                num = DecimalEncoding.DecodeDecimal64(buffer);
            }
            else
            {
                if (num1 != 148)
                {
                    throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
                }
                num = DecimalEncoding.DecodeDecimal128(buffer);
            }
            return(num);
        }
Exemplo n.º 11
0
        public static void VerifyFormatCode(Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode formatCode, int offset, params Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode[] expected)
        {
            bool flag = false;

            Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode[] formatCodeArray = expected;
            int num = 0;

            while (num < (int)formatCodeArray.Length)
            {
                if (formatCode != formatCodeArray[num])
                {
                    num++;
                }
                else
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, offset));
            }
        }
Exemplo n.º 12
0
            protected override void Initialize(ByteBuffer buffer, FormatCode formatCode, out int size, out int count, out int encodeWidth, out SerializableType.CollectionType effectiveType)
            {
                object valueOrDefault;

                if (formatCode != 0)
                {
                    throw new AmqpException(AmqpError.InvalidField, SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
                }
                effectiveType = null;
                formatCode    = AmqpEncoding.ReadFormatCode(buffer);
                ulong?     nullable   = null;
                AmqpSymbol amqpSymbol = new AmqpSymbol();

                if (formatCode == 68)
                {
                    nullable = new ulong?((ulong)0);
                }
                else if (formatCode == 128 || formatCode == 83)
                {
                    nullable = ULongEncoding.Decode(buffer, formatCode);
                }
                else if (formatCode == 163 || formatCode == 179)
                {
                    amqpSymbol = SymbolEncoding.Decode(buffer, formatCode);
                }
                if (this.AreEqual(this.descriptorCode, this.descriptorName, nullable, amqpSymbol))
                {
                    effectiveType = this;
                }
                else if (this.knownTypes != null)
                {
                    int num = 0;
                    while (num < (int)this.knownTypes.Length)
                    {
                        KeyValuePair <Type, SerializableType> keyValuePair = this.knownTypes[num];
                        if (keyValuePair.Value == null)
                        {
                            SerializableType type = this.serializer.GetType(keyValuePair.Key);
                            keyValuePair = new KeyValuePair <Type, SerializableType>(keyValuePair.Key, type);
                            KeyValuePair <Type, SerializableType> keyValuePair1 = keyValuePair;
                            keyValuePair         = keyValuePair1;
                            this.knownTypes[num] = keyValuePair1;
                        }
                        SerializableType.DescribedType value = (SerializableType.DescribedType)keyValuePair.Value;
                        if (!this.AreEqual(value.descriptorCode, value.descriptorName, nullable, amqpSymbol))
                        {
                            num++;
                        }
                        else
                        {
                            effectiveType = value;
                            break;
                        }
                    }
                }
                if (effectiveType == null)
                {
                    ulong?nullable1 = nullable;
                    if (nullable1.HasValue)
                    {
                        valueOrDefault = nullable1.GetValueOrDefault();
                    }
                    else
                    {
                        valueOrDefault = amqpSymbol.Value;
                    }
                    throw new SerializationException(SRAmqp.AmqpUnknownDescriptor(valueOrDefault, this.type.Name));
                }
                formatCode = AmqpEncoding.ReadFormatCode(buffer);
                if (this.Code != 208)
                {
                    encodeWidth = (formatCode == 193 ? 1 : 4);
                    AmqpEncoding.ReadSizeAndCount(buffer, formatCode, 193, 209, out size, out count);
                    return;
                }
                if (formatCode == 69)
                {
                    int num1 = 0;
                    int num2 = num1;
                    encodeWidth = num1;
                    int num3 = num2;
                    int num4 = num3;
                    count = num3;
                    size  = num4;
                    return;
                }
                encodeWidth = (formatCode == 192 ? 1 : 4);
                AmqpEncoding.ReadSizeAndCount(buffer, formatCode, 192, 208, out size, out count);
            }