本文整理汇总了C#中System.Byte.ReversePortion方法的典型用法代码示例。如果您正苦于以下问题:C# Byte.ReversePortion方法的具体用法?C# Byte.ReversePortion怎么用?C# Byte.ReversePortion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Byte
的用法示例。
在下文中一共展示了Byte.ReversePortion方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryParse
public static Boolean TryParse(Byte[] frameStart, Int32 offset, Int32 headerLength, ArraySegment<Byte> keySegment, out WebSocketFrameHeader header)
{
header = null;
if (frameStart == null || frameStart.Length < 6 || frameStart.Length < (offset + headerLength))
return false;
Int32 value = frameStart[offset+1];
UInt64 contentLength = (UInt64)(value>=128?value - 128:value);
if (contentLength <= 125)
{
// small frame
}
else if (contentLength == 126)
{
if (frameStart.Length < headerLength)
return false;
if(BitConverter.IsLittleEndian)
frameStart.ReversePortion(offset + 2, 2);
contentLength = BitConverter.ToUInt16(frameStart, 2);
}
else if (contentLength == 127)
{
if (frameStart.Length < headerLength)
return false;
if (BitConverter.IsLittleEndian)
frameStart.ReversePortion(offset + 2, 8);
contentLength = (UInt64)BitConverter.ToUInt64(frameStart, 2);
}
else
return false;
WebSocketFrameHeaderFlags flags;
if (WebSocketFrameHeaderFlags.TryParse(frameStart, offset, out flags))
{
header = new WebSocketFrameHeader(keySegment)
{
ContentLength = contentLength,
HeaderLength = headerLength,
Flags = flags,
RemainingBytes = contentLength
};
if (flags.MASK)
{
headerLength -= 4;
for (int i = 0; i < 4; i++)
header._key.Array[header._key.Offset + i] = frameStart[offset + i + headerLength];
}
return true;
}
return false;
}
示例2: TryParse
public static Boolean TryParse(Byte[] frameStart, Int32 offset, Int32 headerLength, ArraySegment<Byte> keySegment, out WebSocketFrameHeader header)
{
header = null;
if (frameStart == null || frameStart.Length < 6 || frameStart.Length < (offset + headerLength))
return false;
Int32 value = frameStart[offset+1];
Int64 contentLength = (Int64)(value>=128?value - 128:value);
if (contentLength <= 125)
{
// small frame
}
else if (contentLength == 126)
{
if (frameStart.Length < headerLength)
return false;
if(BitConverter.IsLittleEndian)
frameStart.ReversePortion(offset + 2, 2);
contentLength = BitConverter.ToUInt16(frameStart, 2);
}
else if (contentLength == 127)
{
if (frameStart.Length < headerLength)
return false;
if (BitConverter.IsLittleEndian)
frameStart.ReversePortion(offset + 2, 8);
UInt64 length = BitConverter.ToUInt64(frameStart, 2);
if(length > Int64.MaxValue)
{
throw new WebSocketException("The maximum supported frame length is 9223372036854775807, current frame is " + length.ToString());
}
contentLength = (Int64)length;
}
else
return false;
WebSocketFrameHeaderFlags flags;
if (WebSocketFrameHeaderFlags.TryParse(frameStart, offset, out flags))
{
header = new WebSocketFrameHeader(keySegment)
{
ContentLength = contentLength,
HeaderLength = headerLength,
Flags = flags,
RemainingBytes = contentLength
};
if (flags.MASK)
{
headerLength -= 4;
for (int i = 0; i < 4; i++)
header._key.Array[header._key.Offset + i] = frameStart[offset + i + headerLength];
}
return true;
}
return false;
}