本文整理汇总了C#中CompactBinaryReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# CompactBinaryReader.Read方法的具体用法?C# CompactBinaryReader.Read怎么用?C# CompactBinaryReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CompactBinaryReader
的用法示例。
在下文中一共展示了CompactBinaryReader.Read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadRelayMessageList
/// <summary>
/// Converts the given <see cref="Stream"/> into a list of <see cref="RelayMessage"/>.
/// </summary>
/// <param name="stream">The given <see cref="Stream"/></param>
/// <param name="evaluateMethod">A method to evaluate each <see cref="RelayMessage"/> as it's deserialized.</param>
/// <returns>A list of <see cref="RelayMessage"/>.</returns>
public static List<RelayMessage> ReadRelayMessageList(Stream stream, Action<RelayMessage> evaluateMethod)
{
BinaryReader bread = new BinaryReader(stream);
CompactBinaryReader br = new CompactBinaryReader(bread);
int objectCount = br.ReadInt32();
List<RelayMessage> messages = new List<RelayMessage>(objectCount);
for (int i = 0; i < objectCount; i++)
{
RelayMessage nextMessage = new RelayMessage();
try
{
br.Read<RelayMessage>(nextMessage, false);
}
catch (SerializationException exc)
{
//try and add some context to this object
//Id and TypeId most likely got correctly deserialized so we're providing that much
string message = string.Format("Deserialization failed for RelayMessage of Id='{0}', ExtendedId='{1}', TypeId='{2}' and StreamLength='{3}'",
nextMessage.Id, Algorithm.ToHex(nextMessage.ExtendedId), nextMessage.TypeId, stream.Length);
SerializationException newException = new SerializationException(message, exc);
throw newException;
}
messages.Add(nextMessage);
if (evaluateMethod != null) evaluateMethod(nextMessage);
}
return messages;
}
示例2: Read
public override object Read(CompactBinaryReader reader)
{
int length = reader.ReadInt32();
object[] array = SafeMemoryAllocator.CreateArray<object>(length);
for (int i = 0; i < length; i++) array[i] = reader.Read();
return array;
}