public void handlePacket(byte[] packet) { ByteBuffer rawBuffer = new ByteBuffer(packet); // Check if the size is the realsize short size = rawBuffer.ReadInt16(); rawBuffer.SetIndex(0); if (size < rawBuffer.Length()) { byte[] pck1; pck1 = rawBuffer.ReadBytes(size); buffer.Enqueue(pck1); short size2; size2 = rawBuffer.ReadInt16(); rawBuffer.SetIndex(size); byte[] pck2; pck2 = rawBuffer.ReadBytes(size2); buffer.Enqueue(pck2); } else { buffer.Enqueue(packet); } }
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); }