本文整理汇总了C#中Orleans.Serialization.BinaryTokenStreamReader.ReadBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryTokenStreamReader.ReadBytes方法的具体用法?C# BinaryTokenStreamReader.ReadBytes怎么用?C# BinaryTokenStreamReader.ReadBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orleans.Serialization.BinaryTokenStreamReader
的用法示例。
在下文中一共展示了BinaryTokenStreamReader.ReadBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
public object Deserialize(Type expectedType, BinaryTokenStreamReader reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
var n = reader.ReadInt();
var bytes = reader.ReadBytes(n);
var formatter = new BinaryFormatter();
object retVal = null;
using (var memoryStream = new MemoryStream(bytes))
{
retVal = formatter.Deserialize(memoryStream);
}
return retVal;
}
示例2: Deserialize
/// <summary>
/// Deserializes an object from a binary stream
/// </summary>
/// <param name="expectedType">The type that is expected to be deserialized</param>
/// <param name="reader">The <see cref="BinaryTokenStreamReader"/></param>
/// <returns>The deserialized object</returns>
public object Deserialize(Type expectedType, BinaryTokenStreamReader reader)
{
if (expectedType == null)
{
throw new ArgumentNullException("expectedType");
}
if (reader == null)
{
throw new ArgumentNullException("reader");
}
var typeHandle = expectedType.TypeHandle;
object parser = null;
if (!Parsers.TryGetValue(typeHandle, out parser))
{
throw new ArgumentException("No parser found for the expected type " + expectedType, "expectedType");
}
int length = reader.ReadInt();
if (length == 0)
{
// the special null case.
return null;
}
byte[] data = reader.ReadBytes(length);
dynamic dynamicParser = parser;
object message = dynamicParser.ParseFrom(data);
return message;
}
示例3: Deserializer
public static object Deserializer(Type expected, BinaryTokenStreamReader stream) =>
Deserialize(stream.ReadBytes(stream.ReadInt()));