예제 #1
0
        private static decimal DecodeDecimal64(ByteBuffer buffer)
        {
            byte[] numArray = new byte[8];
            AmqpBitConverter.ReadBytes(buffer, numArray, 0, (int)numArray.Length);
            int num  = 1;
            int num1 = 0;

            num = ((numArray[0] & 128) != 0 ? -1 : 1);
            if ((numArray[0] & 96) != 96)
            {
                num1        = (numArray[0] & 127) << 3 | (numArray[1] & 224) >> 5;
                numArray[0] = 0;
                numArray[1] = (byte)(numArray[1] & 31);
            }
            else if ((numArray[0] & 120) == 0)
            {
                num1        = (numArray[0] & 31) << 8 | (numArray[1] & 248) >> 3;
                numArray[0] = 0;
                numArray[1] = (byte)(numArray[1] & 7);
                numArray[1] = (byte)(numArray[1] | 32);
            }
            int num2 = (int)AmqpBitConverter.ReadUInt(numArray, 0, 4);
            int num3 = (int)AmqpBitConverter.ReadUInt(numArray, 4, 4);

            return(DecimalEncoding.CreateDecimal(num3, num2, 0, num, num1 - 398));
        }
예제 #2
0
        static void Encode(Array value, int width, int encodeSize, ByteBuffer buffer)
        {
            encodeSize -= (FixedWidth.FormatCode + width);
            if (width == FixedWidth.UByte)
            {
                AmqpBitConverter.WriteUByte(buffer, (byte)encodeSize);
                AmqpBitConverter.WriteUByte(buffer, (byte)value.Length);
            }
            else
            {
                AmqpBitConverter.WriteUInt(buffer, (uint)encodeSize);
                AmqpBitConverter.WriteUInt(buffer, (uint)value.Length);
            }

            if (value.Length > 0)
            {
                object       firstItem = value.GetValue(0);
                EncodingBase encoding  = AmqpEncoding.GetEncoding(firstItem);
                AmqpBitConverter.WriteUByte(buffer, (byte)encoding.FormatCode);
                if (encoding.FormatCode == FormatCode.Described)
                {
                    DescribedType describedValue = (DescribedType)firstItem;
                    AmqpEncoding.EncodeObject(describedValue.Descriptor, buffer);
                    AmqpBitConverter.WriteUByte(buffer, (byte)AmqpEncoding.GetEncoding(describedValue.Value).FormatCode);
                }

                foreach (object item in value)
                {
                    encoding.EncodeObject(item, true, buffer);
                }
            }
        }
예제 #3
0
        public static uint PeekUInt(ByteBuffer buffer)
        {
            buffer.Validate(false, 4);
            uint num = AmqpBitConverter.ReadUInt(buffer.Buffer, buffer.Offset, buffer.Length);

            return(num);
        }
예제 #4
0
 private static void Encode(Array value, int width, int encodeSize, ByteBuffer buffer)
 {
     encodeSize = encodeSize - (1 + width);
     if (width != 1)
     {
         AmqpBitConverter.WriteUInt(buffer, (uint)encodeSize);
         AmqpBitConverter.WriteUInt(buffer, (uint)value.Length);
     }
     else
     {
         AmqpBitConverter.WriteUByte(buffer, (byte)encodeSize);
         AmqpBitConverter.WriteUByte(buffer, (byte)value.Length);
     }
     if (value.Length > 0)
     {
         object       obj      = value.GetValue(0);
         EncodingBase encoding = AmqpEncoding.GetEncoding(obj);
         AmqpBitConverter.WriteUByte(buffer, encoding.FormatCode);
         if (encoding.FormatCode == 0)
         {
             DescribedType describedType = (DescribedType)obj;
             AmqpEncoding.EncodeObject(describedType.Descriptor, buffer);
             AmqpBitConverter.WriteUByte(buffer, AmqpEncoding.GetEncoding(describedType.Value).FormatCode);
         }
         foreach (object obj1 in value)
         {
             encoding.EncodeObject(obj1, true, buffer);
         }
     }
 }
예제 #5
0
        unsafe static decimal DecodeDecimal128(ByteBuffer buffer)
        {
            byte[] bytes = new byte[FixedWidth.Decimal128];
            buffer.ReadBytes(bytes, 0, bytes.Length);
            int sign     = 1;
            int exponent = 0;

            sign = (bytes[0] & 0x80) != 0 ? -1 : 1;
            if ((bytes[0] & 0x60) != 0x60)
            {
                // s 14-bit-exponent (0)113-bit-significant
                exponent  = ((bytes[0] & 0x7F) << 7) | ((bytes[1] & 0xFE) >> 1);
                bytes[0]  = 0;
                bytes[1] &= 0x1;
            }
            else if ((bytes[0] & 0x78) != 0)
            {
                // handle NaN and Infinity
            }
            else
            {
                // s 11 14-bit-exponent (100)111-bit-significant
                // it is out of the valid range already. Should not be used
                return(0);
            }

            int high   = (int)AmqpBitConverter.ReadUInt(bytes, 4, 4);
            int middle = (int)AmqpBitConverter.ReadUInt(bytes, 8, 4);
            int low    = (int)AmqpBitConverter.ReadUInt(bytes, 12, 4);

            return(CreateDecimal(low, middle, high, sign, exponent - Decimal128Bias));
        }
예제 #6
0
        static decimal DecodeDecimal64(ByteBuffer buffer)
        {
            byte[] bytes = new byte[FixedWidth.Decimal64];
            buffer.ReadBytes(bytes, 0, bytes.Length);
            int sign     = 1;
            int exponent = 0;

            sign = (bytes[0] & 0x80) != 0 ? -1 : 1;
            if ((bytes[0] & 0x60) != 0x60)
            {
                // s 10-bit-exponent (0)53-bit-significant
                exponent  = ((bytes[0] & 0x7F) << 3) | ((bytes[1] & 0xE0) >> 5);
                bytes[0]  = 0;
                bytes[1] &= 0x1F;
            }
            else if ((bytes[0] & 0x78) != 0)
            {
                // handle NaN and Infinity
            }
            else
            {
                // s 11 10-bit-exponent (100)51-bit-significant
                exponent  = ((bytes[0] & 0x1F) << 8) | ((bytes[1] & 0xF8) >> 3);
                bytes[0]  = 0;
                bytes[1] &= 0x7;
                bytes[1] |= 0x20;
            }

            int middle = (int)AmqpBitConverter.ReadUInt(bytes, 0, 4);
            int low    = (int)AmqpBitConverter.ReadUInt(bytes, 4, 4);

            return(CreateDecimal(low, middle, 0, sign, exponent - Decimal64Bias));
        }
예제 #7
0
        unsafe static decimal DecodeDecimal32(ByteBuffer buffer)
        {
            byte[] bytes = new byte[FixedWidth.Decimal32];
            buffer.ReadBytes(bytes, 0, bytes.Length);
            int sign     = 1;
            int exponent = 0;

            sign = (bytes[0] & 0x80) != 0 ? -1 : 1;
            if ((bytes[0] & 0x60) != 0x60)
            {
                // s 8-bit-exponent (0)23-bit-significant
                exponent  = ((bytes[0] & 0x7F) << 1) | ((bytes[1] & 0x80) >> 7);
                bytes[0]  = 0;
                bytes[1] &= 0x7F;
            }
            else if ((bytes[0] & 0x78) != 0)
            {
                // handle NaN and Infinity
            }
            else
            {
                // s 11 8-bit-exponent (100)21-bit-significant
                exponent  = ((bytes[0] & 0x1F) << 3) | ((bytes[1] & 0xE0) >> 5);
                bytes[0]  = 0;
                bytes[1] &= 0x1F;
                bytes[1] |= 0x80;
            }

            int low = (int)AmqpBitConverter.ReadUInt(bytes, 0, bytes.Length);

            return(CreateDecimal(low, 0, 0, sign, exponent - Decimal32Bias));
        }
예제 #8
0
        private static unsafe void EncodeValue(decimal value, ByteBuffer buffer)
        {
            int[] bits = decimal.GetBits(value);
            int   num  = bits[0];
            int   num1 = bits[1];
            int   num2 = bits[2];
            int   num3 = bits[3];

            byte[] numArray   = new byte[16];
            byte * numPointer = (byte *)(&num3);
            int    num4       = 6176 - *(numPointer + 2);

            numArray[0]  = *(numPointer + 3);
            numArray[0]  = (byte)(numArray[0] | (byte)(num4 >> 9));
            numArray[1]  = (byte)((num4 & 127) << 1);
            numArray[2]  = 0;
            numArray[3]  = 0;
            numPointer   = (byte *)(&num2);
            numArray[4]  = *(numPointer + 3);
            numArray[5]  = *(numPointer + 2);
            numArray[6]  = *(numPointer + 1);
            numArray[7]  = *numPointer;
            numPointer   = (byte *)(&num1);
            numArray[8]  = *(numPointer + 3);
            numArray[9]  = *(numPointer + 2);
            numArray[10] = *(numPointer + 1);
            numArray[11] = *numPointer;
            numPointer   = (byte *)(&num);
            numArray[12] = *(numPointer + 3);
            numArray[13] = *(numPointer + 2);
            numArray[14] = *(numPointer + 1);
            numArray[15] = *numPointer;
            AmqpBitConverter.WriteBytes(buffer, numArray, 0, (int)numArray.Length);
        }
예제 #9
0
        public static ulong ReadULong(ByteBuffer buffer)
        {
            buffer.Validate(false, 8);
            ulong num = AmqpBitConverter.ReadULong(buffer.Buffer, buffer.Offset, buffer.Length);

            buffer.Complete(8);
            return(num);
        }
예제 #10
0
        public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
        {
            Array array = (Array)value;
            int   width;
            int   encodeSize = ArrayEncoding.GetEncodeSize(array, arrayEncoding, out width);

            AmqpBitConverter.WriteUByte(buffer, width == FixedWidth.UByte ? (byte)FormatCode.Array8 : (byte)FormatCode.Array32);
            ArrayEncoding.Encode(array, width, encodeSize, buffer);
        }
예제 #11
0
        public static Guid?Decode(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null)
            {
                return(null);
            }

            return(AmqpBitConverter.ReadUuid(buffer));
        }
예제 #12
0
        public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
        {
            int   num;
            Array arrays     = (Array)value;
            int   encodeSize = ArrayEncoding.GetEncodeSize(arrays, arrayEncoding, out num);

            AmqpBitConverter.WriteUByte(buffer, (byte)((num == 1 ? 224 : 240)));
            ArrayEncoding.Encode(arrays, num, encodeSize, buffer);
        }
예제 #13
0
 public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
 {
     if (arrayEncoding)
     {
         AmqpBitConverter.WriteULong(buffer, (ulong)value);
         return;
     }
     ULongEncoding.Encode(new ulong?((ulong)value), buffer);
 }
예제 #14
0
 public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
 {
     if (arrayEncoding)
     {
         AmqpBitConverter.WriteUuid(buffer, (Guid)value);
         return;
     }
     UuidEncoding.Encode(new Guid?((Guid)value), buffer);
 }
예제 #15
0
 public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
 {
     if (!arrayEncoding)
     {
         CharEncoding.Encode(new char?((char)value), buffer);
         return;
     }
     AmqpBitConverter.WriteInt(buffer, char.ConvertToUtf32(new string((char)value, 1), 0));
 }
예제 #16
0
 public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
 {
     if (arrayEncoding)
     {
         AmqpBitConverter.WriteFloat(buffer, (float)value);
         return;
     }
     FloatEncoding.Encode(new float?((float)value), buffer);
 }
예제 #17
0
 public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
 {
     if (arrayEncoding)
     {
         AmqpBitConverter.WriteDouble(buffer, (double)value);
         return;
     }
     DoubleEncoding.Encode(new double?((double)value), buffer);
 }
예제 #18
0
 public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
 {
     if (arrayEncoding)
     {
         AmqpBitConverter.WriteShort(buffer, (short)value);
         return;
     }
     ShortEncoding.Encode(new short?((short)value), buffer);
 }
예제 #19
0
 public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
 {
     if (arrayEncoding)
     {
         AmqpBitConverter.WriteUByte(buffer, (byte)value);
         return;
     }
     UByteEncoding.Encode(new byte?((byte)value), buffer);
 }
예제 #20
0
 public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
 {
     if (arrayEncoding)
     {
         AmqpBitConverter.WriteLong(buffer, TimeStampEncoding.GetMilliseconds((DateTime)value));
         return;
     }
     TimeStampEncoding.Encode(new DateTime?((DateTime)value), buffer);
 }
예제 #21
0
 public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
 {
     if (arrayEncoding)
     {
         AmqpBitConverter.WriteInt(buffer, (int)value);
         return;
     }
     IntEncoding.Encode(new int?((int)value), buffer);
 }
예제 #22
0
 public static void Encode(bool?value, ByteBuffer buffer)
 {
     if (!value.HasValue)
     {
         AmqpEncoding.EncodeNull(buffer);
         return;
     }
     AmqpBitConverter.WriteUByte(buffer, (byte)((value.Value ? 65 : 66)));
 }
예제 #23
0
 public static void Encode(char?value, ByteBuffer buffer)
 {
     if (!value.HasValue)
     {
         AmqpEncoding.EncodeNull(buffer);
         return;
     }
     AmqpBitConverter.WriteUByte(buffer, 115);
     AmqpBitConverter.WriteInt(buffer, char.ConvertToUtf32(new string(value.Value, 1), 0));
 }
예제 #24
0
 public static void Encode(DateTime?value, ByteBuffer buffer)
 {
     if (!value.HasValue)
     {
         AmqpEncoding.EncodeNull(buffer);
         return;
     }
     AmqpBitConverter.WriteUByte(buffer, 131);
     AmqpBitConverter.WriteLong(buffer, TimeStampEncoding.GetMilliseconds(value.Value));
 }
예제 #25
0
 public static void Encode(decimal?value, ByteBuffer buffer)
 {
     if (!value.HasValue)
     {
         AmqpEncoding.EncodeNull(buffer);
         return;
     }
     AmqpBitConverter.WriteUByte(buffer, 148);
     DecimalEncoding.EncodeValue(value.Value, buffer);
 }
예제 #26
0
 public static void Encode(byte?value, ByteBuffer buffer)
 {
     if (!value.HasValue)
     {
         AmqpEncoding.EncodeNull(buffer);
         return;
     }
     AmqpBitConverter.WriteUByte(buffer, 80);
     AmqpBitConverter.WriteUByte(buffer, value.Value);
 }
예제 #27
0
 public static void Encode(DescribedType value, ByteBuffer buffer)
 {
     if (value.Value == null)
     {
         AmqpEncoding.EncodeNull(buffer);
         return;
     }
     AmqpBitConverter.WriteUByte(buffer, 0);
     AmqpEncoding.EncodeObject(value.Descriptor, buffer);
     AmqpEncoding.EncodeObject(value.Value, buffer);
 }
예제 #28
0
        public static unsafe void WriteUShort(byte[] buffer, int offset, ushort data)
        {
            AmqpBitConverter.Validate((int)buffer.Length - offset, 2);
            fixed(byte *numPointer = &buffer[offset])
            {
                byte *numPointer1 = (byte *)(&data);

                *numPointer = *(numPointer1 + 1);
                *(numPointer + 1) = *numPointer1;
            }
        }
예제 #29
0
        public static FormatCode ReadFormatCode(ByteBuffer buffer)
        {
            int formatCode = AmqpBitConverter.ReadUByte(buffer);

            if ((formatCode & 0x0F) == 0x0F)
            {
                formatCode = (formatCode << 8) + AmqpBitConverter.ReadUByte(buffer);
            }

            return((FormatCode)formatCode);
        }
예제 #30
0
        public static FormatCode ReadFormatCode(ByteBuffer buffer)
        {
            byte num  = AmqpBitConverter.ReadUByte(buffer);
            byte num1 = 0;

            if (FormatCode.HasExtType(num))
            {
                num1 = AmqpBitConverter.ReadUByte(buffer);
            }
            return(new FormatCode(num, num1));
        }