ReadUuid() public static method

public static ReadUuid ( System.ByteBuffer buffer ) : System.Guid
buffer System.ByteBuffer
return System.Guid
Beispiel #1
0
        public static Guid?Decode(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null)
            {
                return(null);
            }

            return(AmqpBitConverter.ReadUuid(buffer));
        }
Beispiel #2
0
        static T[] Decode <T>(ByteBuffer buffer, int size, int count, FormatCode formatCode)
        {
            object descriptor = null;

            if (formatCode == FormatCode.Described)
            {
                descriptor = AmqpEncoding.DecodeObject(buffer);
                formatCode = AmqpEncoding.ReadFormatCode(buffer);
            }

            // Special cases for primitive types
            switch (formatCode)
            {
            case FormatCode.UInt0:
            case FormatCode.SmallUInt:
                return((T[])DecodeArray <uint>(buffer, formatCode, count, (b, f) => UIntEncoding.Decode(b, f).Value));

            case FormatCode.UInt:
                return((T[])DecodeArray <uint>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadUInt(b)));

            case FormatCode.SmallInt:
                return((T[])DecodeArray <int>(buffer, formatCode, count, (b, f) => IntEncoding.Decode(b, f).Value));

            case FormatCode.Int:
                return((T[])DecodeArray <int>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadInt(b)));

            case FormatCode.ULong0:
            case FormatCode.SmallULong:
                return((T[])DecodeArray <ulong>(buffer, formatCode, count, (b, f) => ULongEncoding.Decode(b, f).Value));

            case FormatCode.ULong:
                return((T[])DecodeArray <ulong>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadULong(b)));

            case FormatCode.SmallLong:
                return((T[])DecodeArray <long>(buffer, formatCode, count, (b, f) => LongEncoding.Decode(b, f).Value));

            case FormatCode.Long:
                return((T[])DecodeArray <long>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadLong(b)));

            case FormatCode.Symbol8:
            case FormatCode.Symbol32:
                return((T[])DecodeArray <AmqpSymbol>(buffer, formatCode, count, (b, f) => SymbolEncoding.Decode(b, f)));

            case FormatCode.Boolean:
                return((T[])DecodeArray <bool>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadUByte(b) > 0));

            case FormatCode.UByte:
                return((T[])DecodeArray <byte>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadUByte(b)));

            case FormatCode.Byte:
                return((T[])DecodeArray <sbyte>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadByte(b)));

            case FormatCode.UShort:
                return((T[])DecodeArray <ushort>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadUShort(b)));

            case FormatCode.Short:
                return((T[])DecodeArray <short>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadShort(b)));

            case FormatCode.Float:
                return((T[])DecodeArray <float>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadFloat(b)));

            case FormatCode.Double:
                return((T[])DecodeArray <double>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadDouble(b)));

            case FormatCode.Decimal32:
            case FormatCode.Decimal64:
            case FormatCode.Decimal128:
                return((T[])DecodeArray <decimal>(buffer, formatCode, count, (b, f) => DecimalEncoding.DecodeValue(b, f)));

            case FormatCode.Char:
                return((T[])DecodeArray <char>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadChar(b)));

            case FormatCode.TimeStamp:
                return((T[])DecodeArray <DateTime>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadTimestamp(b)));

            case FormatCode.Uuid:
                return((T[])DecodeArray <Guid>(buffer, formatCode, count, (b, f) => AmqpBitConverter.ReadUuid(b)));

            default:
                break;
            }

            // General path
            EncodingBase encoding = AmqpEncoding.GetEncoding(formatCode);

            T[] array = new T[count];
            for (int i = 0; i < count; ++i)
            {
                object value = encoding.DecodeObject(buffer, formatCode);
                if (descriptor != null)
                {
                    value = new DescribedType(descriptor, value);
                }

                array[i] = (T)value;
            }

            return(array);
        }