本文整理匯總了C#中BigEndianBinaryReader.Available方法的典型用法代碼示例。如果您正苦於以下問題:C# BigEndianBinaryReader.Available方法的具體用法?C# BigEndianBinaryReader.Available怎麽用?C# BigEndianBinaryReader.Available使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BigEndianBinaryReader
的用法示例。
在下文中一共展示了BigEndianBinaryReader.Available方法的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;
}
}
}
}