本文整理匯總了C#中System.ByteBuffer.ReadBytes方法的典型用法代碼示例。如果您正苦於以下問題:C# ByteBuffer.ReadBytes方法的具體用法?C# ByteBuffer.ReadBytes怎麽用?C# ByteBuffer.ReadBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.ReadBytes方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: handlePacket
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);
}
}
示例2: DecodeDecimal128
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);
}
示例3: DecodeDecimal64
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);
}
示例4: DecodeDecimal32
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);
}