当前位置: 首页>>代码示例>>C#>>正文


C# CompactBinaryReader.Read方法代码示例

本文整理汇总了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;
		}
开发者ID:edwardt,项目名称:MySpace-Data-Relay,代码行数:33,代码来源:RelayMessageFormatter.cs

示例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;
		}
开发者ID:edwardt,项目名称:MySpace-Data-Relay,代码行数:7,代码来源:BuiltinSurrogates.cs


注:本文中的CompactBinaryReader.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。