本文整理汇总了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);
}