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)); }
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); } } }
public static uint PeekUInt(ByteBuffer buffer) { buffer.Validate(false, 4); uint num = AmqpBitConverter.ReadUInt(buffer.Buffer, buffer.Offset, buffer.Length); return(num); }
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); } } }
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)); }
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)); }
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)); }
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); }
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); }
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); }
public static Guid?Decode(ByteBuffer buffer, FormatCode formatCode) { if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null) { return(null); } return(AmqpBitConverter.ReadUuid(buffer)); }
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); }
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); }
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); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
public static void Encode(bool?value, ByteBuffer buffer) { if (!value.HasValue) { AmqpEncoding.EncodeNull(buffer); return; } AmqpBitConverter.WriteUByte(buffer, (byte)((value.Value ? 65 : 66))); }
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)); }
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)); }
public static void Encode(decimal?value, ByteBuffer buffer) { if (!value.HasValue) { AmqpEncoding.EncodeNull(buffer); return; } AmqpBitConverter.WriteUByte(buffer, 148); DecimalEncoding.EncodeValue(value.Value, buffer); }
public static void Encode(byte?value, ByteBuffer buffer) { if (!value.HasValue) { AmqpEncoding.EncodeNull(buffer); return; } AmqpBitConverter.WriteUByte(buffer, 80); AmqpBitConverter.WriteUByte(buffer, value.Value); }
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); }
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; } }
public static FormatCode ReadFormatCode(ByteBuffer buffer) { int formatCode = AmqpBitConverter.ReadUByte(buffer); if ((formatCode & 0x0F) == 0x0F) { formatCode = (formatCode << 8) + AmqpBitConverter.ReadUByte(buffer); } return((FormatCode)formatCode); }
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)); }