コード例 #1
0
ファイル: StringEncoding.cs プロジェクト: Azure/azure-amqp
        public static string Decode(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null)
            {
                return null;
            }

            int count;
            Encoding encoding;

            if (formatCode == FormatCode.String8Utf8)
            {
                count = (int)AmqpBitConverter.ReadUByte(buffer);
                encoding = Encoding.UTF8;
            }
            else if (formatCode == FormatCode.String32Utf8)
            {
                count = (int)AmqpBitConverter.ReadUInt(buffer);
                encoding = Encoding.UTF8;
            }
            else
            {
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
            }

            string value = encoding.GetString(buffer.Buffer, buffer.Offset, count);
            buffer.Complete(count);

            return value;
        }
コード例 #2
0
ファイル: ListEncoding.cs プロジェクト: Azure/azure-amqp
        public static IList Decode(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null)
            {
                return null;
            }

            IList list = new List<object>();
            if (formatCode == FormatCode.List0)
            {
                return list;
            }

            int size;
            int count;
            AmqpEncoding.ReadSizeAndCount(buffer, formatCode, FormatCode.List8, FormatCode.List32, out size, out count);

            for (; count > 0; --count)
            {
                object item = AmqpEncoding.DecodeObject(buffer);
                list.Add(item);
            }

            return list;
        }
コード例 #3
0
ファイル: DecimalEncoding.cs プロジェクト: Azure/azure-amqp
        public static decimal? Decode(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null)
            {
                return null;
            }

            return DecimalEncoding.DecodeValue(buffer, formatCode);
        }
コード例 #4
0
ファイル: UuidEncoding.cs プロジェクト: Azure/azure-amqp
        public static Guid? Decode(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null)
            {
                return null;
            }

            return AmqpBitConverter.ReadUuid(buffer);
        }
コード例 #5
0
ファイル: MapEncoding.cs プロジェクト: Azure/azure-amqp
        public static AmqpMap Decode(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null)
            {
                return null;
            }

            int size;
            int count;
            AmqpEncoding.ReadSizeAndCount(buffer, formatCode, FormatCode.Map8, FormatCode.Map32, out size, out count);
            AmqpMap map = new AmqpMap();
            MapEncoding.ReadMapValue(buffer, map, size, count);
            return map;
        }
コード例 #6
0
ファイル: SymbolEncoding.cs プロジェクト: Azure/azure-amqp
        public static AmqpSymbol Decode(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null)
            {
                return new AmqpSymbol();
            }

            int count;
            AmqpEncoding.ReadCount(buffer, formatCode, FormatCode.Symbol8, FormatCode.Symbol32, out count);
            string value = Platform.System.Text.Encoding.ASCII.GetString(buffer.Buffer, buffer.Offset, count);
            buffer.Complete(count);

            return new AmqpSymbol(value);
        }
コード例 #7
0
ファイル: SerializableType.cs プロジェクト: Azure/azure-amqp
            protected override void Initialize(ByteBuffer buffer, FormatCode formatCode,
                out int size, out int count, out int encodeWidth, out Collection effectiveType)
            {
                if (formatCode != FormatCode.Described)
                {
                    throw new AmqpException(AmqpErrorCode.InvalidField, AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
                }

                effectiveType = null;
                formatCode = AmqpEncoding.ReadFormatCode(buffer);
                ulong? code = null;
                AmqpSymbol symbol = default(AmqpSymbol);
                if (formatCode == FormatCode.ULong0)
                {
                    code = 0;
                }
                else if (formatCode == FormatCode.ULong || formatCode == FormatCode.SmallULong)
                {
                    code = ULongEncoding.Decode(buffer, formatCode);
                }
                else if (formatCode == FormatCode.Symbol8 || formatCode == FormatCode.Symbol32)
                {
                    symbol = SymbolEncoding.Decode(buffer, formatCode);
                }

                if (this.AreEqual(this.descriptorCode, this.descriptorName, code, symbol))
                {
                    effectiveType = this;
                }
                else if (this.knownTypes != null)
                {
                    for (int i = 0; i < this.knownTypes.Length; ++i)
                    {
                        var kvp = this.knownTypes[i];
                        if (kvp.Value == null)
                        {
                            SerializableType knownType = this.serializer.GetType(kvp.Key);
                            this.knownTypes[i] = kvp = new KeyValuePair<Type, SerializableType>(kvp.Key, knownType);
                        }

                        Composite describedKnownType = (Composite)kvp.Value;
                        if (this.AreEqual(describedKnownType.descriptorCode, describedKnownType.descriptorName, code, symbol))
                        {
                            effectiveType = describedKnownType;
                            break;
                        }
                    }
                }

                if (effectiveType == null)
                {
                    throw new SerializationException(AmqpResources.GetString(AmqpResources.AmqpUnknownDescriptor, code ?? (object)symbol.Value, this.type.Name));
                }

                formatCode = AmqpEncoding.ReadFormatCode(buffer);
                if (this.Code == FormatCode.List32)
                {
                    if (formatCode == FormatCode.List0)
                    {
                        size = count = encodeWidth = 0;
                    }
                    else
                    {
                        encodeWidth = formatCode == FormatCode.List8 ? FixedWidth.UByte : FixedWidth.UInt;
                        AmqpEncoding.ReadSizeAndCount(buffer, formatCode, FormatCode.List8,
                            FormatCode.List32, out size, out count);
                    }
                }
                else
                {
                    encodeWidth = formatCode == FormatCode.Map8 ? FixedWidth.UByte : FixedWidth.UInt;
                    AmqpEncoding.ReadSizeAndCount(buffer, formatCode, FormatCode.Map8,
                        FormatCode.Map32, out size, out count);
                }
            }
コード例 #8
0
ファイル: SerializableType.cs プロジェクト: Azure/azure-amqp
            protected override void Initialize(ByteBuffer buffer, FormatCode formatCode,
                out int size, out int count, out int encodeWidth, out Collection effectiveType)
            {
                if (formatCode != FormatCode.Map32 && formatCode != FormatCode.Map8)
                {
                    throw new AmqpException(AmqpErrorCode.InvalidField, AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
                }

                encodeWidth = formatCode == FormatCode.Map8 ? FixedWidth.UByte : FixedWidth.UInt;
                AmqpEncoding.ReadSizeAndCount(buffer, formatCode, FormatCode.Map8, FormatCode.Map32, out size, out count);
                effectiveType = this;
            }
コード例 #9
0
ファイル: SerializableType.cs プロジェクト: Azure/azure-amqp
 protected abstract void Initialize(ByteBuffer buffer, FormatCode formatCode,
     out int size, out int count, out int encodeWidth, out Collection effectiveType);
コード例 #10
0
ファイル: DecimalEncoding.cs プロジェクト: Azure/azure-amqp
        static decimal DecodeValue(ByteBuffer buffer, FormatCode formatCode)
        {
            decimal value = 0;
            switch (formatCode)
            {
                case FormatCode.Decimal32:
                    value = DecimalEncoding.DecodeDecimal32(buffer);
                    break;
                case FormatCode.Decimal64:
                    value = DecimalEncoding.DecodeDecimal64(buffer);
                    break;
                case FormatCode.Decimal128:
                    value = DecimalEncoding.DecodeDecimal128(buffer);
                    break;
                default:
                    throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
            }

            return value;
        }
コード例 #11
0
ファイル: AmqpEncoding.cs プロジェクト: Azure/azure-amqp
        public static object DecodeObject(ByteBuffer buffer, FormatCode formatCode)
        {
            EncodingBase encoding;
            if (encodingsByCode.TryGetValue(formatCode, out encoding))
            {
                return encoding.DecodeObject(buffer, formatCode);
            }

            throw GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
        }
コード例 #12
0
 public override object DecodeObject(ByteBuffer buffer, FormatCode formatCode)
 {
     return(DecimalEncoding.Decode(buffer, formatCode));
 }
コード例 #13
0
ファイル: AmqpEncoding.cs プロジェクト: Azure/azure-amqp
        public static EncodingBase GetEncoding(FormatCode formatCode)
        {
            EncodingBase encoding;
            if (encodingsByCode.TryGetValue(formatCode, out encoding))
            {
                return encoding;
            }

            return null;
        }
コード例 #14
0
        public override object DecodeObject(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null)
            {
                return(null);
            }

            int size  = 0;
            int count = 0;

            AmqpEncoding.ReadSizeAndCount(buffer, formatCode, FormatCode.Array8, FormatCode.Array32, out size, out count);

            formatCode = AmqpEncoding.ReadFormatCode(buffer);
            Array array = null;

            switch (formatCode)
            {
            case FormatCode.Boolean:
                array = ArrayEncoding.Decode <bool>(buffer, size, count, formatCode);
                break;

            case FormatCode.UByte:
                array = ArrayEncoding.Decode <byte>(buffer, size, count, formatCode);
                break;

            case FormatCode.UShort:
                array = ArrayEncoding.Decode <ushort>(buffer, size, count, formatCode);
                break;

            case FormatCode.UInt:
            case FormatCode.SmallUInt:
                array = ArrayEncoding.Decode <uint>(buffer, size, count, formatCode);
                break;

            case FormatCode.ULong:
            case FormatCode.SmallULong:
                array = ArrayEncoding.Decode <ulong>(buffer, size, count, formatCode);
                break;

            case FormatCode.Byte:
                array = ArrayEncoding.Decode <sbyte>(buffer, size, count, formatCode);
                break;

            case FormatCode.Short:
                array = ArrayEncoding.Decode <short>(buffer, size, count, formatCode);
                break;

            case FormatCode.Int:
            case FormatCode.SmallInt:
                array = ArrayEncoding.Decode <int>(buffer, size, count, formatCode);
                break;

            case FormatCode.Long:
            case FormatCode.SmallLong:
                array = ArrayEncoding.Decode <long>(buffer, size, count, formatCode);
                break;

            case FormatCode.Float:
                array = ArrayEncoding.Decode <float>(buffer, size, count, formatCode);
                break;

            case FormatCode.Double:
                array = ArrayEncoding.Decode <double>(buffer, size, count, formatCode);
                break;

            case FormatCode.Char:
                array = ArrayEncoding.Decode <char>(buffer, size, count, formatCode);
                break;

            case FormatCode.TimeStamp:
                array = ArrayEncoding.Decode <DateTime>(buffer, size, count, formatCode);
                break;

            case FormatCode.Uuid:
                array = ArrayEncoding.Decode <Guid>(buffer, size, count, formatCode);
                break;

            case FormatCode.Binary32:
            case FormatCode.Binary8:
                array = ArrayEncoding.Decode <ArraySegment <byte> >(buffer, size, count, formatCode);
                break;

            case FormatCode.String32Utf8:
            case FormatCode.String8Utf8:
                array = ArrayEncoding.Decode <string>(buffer, size, count, formatCode);
                break;

            case FormatCode.Symbol32:
            case FormatCode.Symbol8:
                array = ArrayEncoding.Decode <AmqpSymbol>(buffer, size, count, formatCode);
                break;

            case FormatCode.List32:
            case FormatCode.List8:
                array = ArrayEncoding.Decode <IList>(buffer, size, count, formatCode);
                break;

            case FormatCode.Map32:
            case FormatCode.Map8:
                array = ArrayEncoding.Decode <AmqpMap>(buffer, size, count, formatCode);
                break;

            case FormatCode.Array32:
            case FormatCode.Array8:
                array = ArrayEncoding.Decode <Array>(buffer, size, count, formatCode);
                break;

            default:
                throw new NotSupportedException(CommonResources.GetString(CommonResources.NotSupportFrameCode, formatCode));
            }

            return(array);
        }
コード例 #15
0
 internal static void ReadSizeAndCount(ByteBuffer buffer, FormatCode formatCode, FormatCode formatCode8, FormatCode formatCode32, out int size, out int count)
 {
     if (formatCode == formatCode8)
     {
         size  = AmqpBitConverter.ReadUByte(buffer);
         count = AmqpBitConverter.ReadUByte(buffer);
     }
     else if (formatCode == formatCode32)
     {
         size  = (int)AmqpBitConverter.ReadUInt(buffer);
         count = (int)AmqpBitConverter.ReadUInt(buffer);
     }
     else
     {
         throw GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
     }
 }
コード例 #16
0
ファイル: ListEncoding.cs プロジェクト: Azure/azure-amqp
 public override object DecodeObject(ByteBuffer buffer, FormatCode formatCode)
 {
     return ListEncoding.Decode(buffer, formatCode);
 }
コード例 #17
0
ファイル: AmqpEncoding.cs プロジェクト: Azure/azure-amqp
 public static void ReadSizeAndCount(ByteBuffer buffer, FormatCode formatCode, FormatCode formatCode8, FormatCode formatCode32, out int size, out int count)
 {
     if (formatCode == formatCode8)
     {
         size = AmqpBitConverter.ReadUByte(buffer);
         count = AmqpBitConverter.ReadUByte(buffer);
     }
     else if (formatCode == formatCode32)
     {
         size = (int)AmqpBitConverter.ReadUInt(buffer);
         count = (int)AmqpBitConverter.ReadUInt(buffer);
     }
     else
     {
         throw GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
     }
 }
コード例 #18
0
 public static ArraySegment <byte> Decode(ByteBuffer buffer, FormatCode formatCode)
 {
     return(Decode(buffer, formatCode, true));
 }