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

            int      count    = 0;
            Encoding encoding = null;

            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.GetInvalidFormatCodeException(formatCode, buffer.Offset);
            }

            ArraySegment <byte> bytes = buffer.GetBytes(count);

            return(encoding.GetString(bytes.Array, bytes.Offset, count));
        }
Beispiel #2
0
        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.GetInvalidFormatCodeException(formatCode, buffer.Offset);
            }
            ;

            return(value);
        }