本文整理汇总了C#中BigEndianBinaryReader.RawRead方法的典型用法代码示例。如果您正苦于以下问题:C# BigEndianBinaryReader.RawRead方法的具体用法?C# BigEndianBinaryReader.RawRead怎么用?C# BigEndianBinaryReader.RawRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigEndianBinaryReader
的用法示例。
在下文中一共展示了BigEndianBinaryReader.RawRead方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecodeMessageSet
/// <summary>
/// Decode a byte[] that represents a collection of messages.
/// </summary>
/// <param name="messageSet">The byte[] encode as a message set from kafka.</param>
/// <returns>Enumerable representing stream of messages decoded from byte[]</returns>
public static IEnumerable<Message> DecodeMessageSet(byte[] messageSet)
{
using (var stream = new BigEndianBinaryReader(messageSet))
{
while (stream.HasData)
{
//this checks that we have at least the minimum amount of data to retrieve a header
if (stream.Available(MessageHeaderSize) == false)
yield break;
var offset = stream.ReadInt64();
var messageSize = stream.ReadInt32();
//if messagessize is greater than the total payload, our max buffer is insufficient.
if ((stream.Length - MessageHeaderSize) < messageSize)
throw new BufferUnderRunException(MessageHeaderSize, messageSize);
//if the stream does not have enough left in the payload, we got only a partial message
if (stream.Available(messageSize) == false)
yield break;
foreach (var message in DecodeMessage(offset, stream.RawRead(messageSize)))
{
yield return message;
}
}
}
}