本文整理汇总了C#中Orleans.Serialization.BinaryTokenStreamWriter.ToBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryTokenStreamWriter.ToBytes方法的具体用法?C# BinaryTokenStreamWriter.ToBytes怎么用?C# BinaryTokenStreamWriter.ToBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orleans.Serialization.BinaryTokenStreamWriter
的用法示例。
在下文中一共展示了BinaryTokenStreamWriter.ToBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UniqueKeySerializationShouldReproduceAnIdenticalObject
public void UniqueKeySerializationShouldReproduceAnIdenticalObject()
{
{
var expected = UniqueKey.NewKey(Guid.NewGuid());
BinaryTokenStreamWriter writer = new BinaryTokenStreamWriter();
writer.Write(expected);
BinaryTokenStreamReader reader = new BinaryTokenStreamReader(writer.ToBytes());
var actual = reader.ReadUniqueKey();
Assert.AreEqual(expected, actual, "UniqueKey.Serialize() and UniqueKey.Deserialize() failed to reproduce an identical object (case #1).");
}
{
var kx = random.Next().ToString(CultureInfo.InvariantCulture);
var expected = UniqueKey.NewKey(Guid.NewGuid(), category: UniqueKey.Category.KeyExtGrain, keyExt: kx);
BinaryTokenStreamWriter writer = new BinaryTokenStreamWriter();
writer.Write(expected);
BinaryTokenStreamReader reader = new BinaryTokenStreamReader(writer.ToBytes());
var actual = reader.ReadUniqueKey();
Assert.AreEqual(expected, actual, "UniqueKey.Serialize() and UniqueKey.Deserialize() failed to reproduce an identical object (case #2).");
}
{
var kx = random.Next().ToString(CultureInfo.InvariantCulture) + new String('*', 400);
var expected = UniqueKey.NewKey(Guid.NewGuid(), category: UniqueKey.Category.KeyExtGrain, keyExt: kx);
BinaryTokenStreamWriter writer = new BinaryTokenStreamWriter();
writer.Write(expected);
BinaryTokenStreamReader reader = new BinaryTokenStreamReader(writer.ToBytes());
var actual = reader.ReadUniqueKey();
Assert.AreEqual(expected, actual, "UniqueKey.Serialize() and UniqueKey.Deserialize() failed to reproduce an identical object (case #3).");
}
}
示例2: Serialize_CustomSerializer
public void Serialize_CustomSerializer()
{
var original = new ClassWithCustomSerializer() { IntProperty = -3, StringProperty = "Goodbye" };
var writeStream = new BinaryTokenStreamWriter();
SerializationManager.Serialize(original, writeStream);
Assert.AreEqual(1, ClassWithCustomSerializer.SerializeCounter, "Custom serializer was not called");
var readStream = new BinaryTokenStreamReader(writeStream.ToBytes());
var obj = SerializationManager.Deserialize(readStream);
Assert.AreEqual(1, ClassWithCustomSerializer.DeserializeCounter, "Custom deserializer was not called");
}
示例3: Serialize_Impl
private List<ArraySegment<byte>> Serialize_Impl(out int headerLengthOut, out int bodyLengthOut)
{
var headerStream = new BinaryTokenStreamWriter();
SerializationManager.SerializeMessageHeaders(Headers, headerStream);
if (bodyBytes == null)
{
var bodyStream = new BinaryTokenStreamWriter();
SerializationManager.Serialize(bodyObject, bodyStream);
// We don't bother to turn this into a byte array and save it in bodyBytes because Serialize only gets called on a message
// being sent off-box. In this case, the likelihood of needed to re-serialize is very low, and the cost of capturing the
// serialized bytes from the steam -- where they're a list of ArraySegment objects -- into an array of bytes is actually
// pretty high (an array allocation plus a bunch of copying).
bodyBytes = bodyStream.ToBytes() as List<ArraySegment<byte>>;
}
if (headerBytes != null)
{
BufferPool.GlobalPool.Release(headerBytes);
}
headerBytes = headerStream.ToBytes() as List<ArraySegment<byte>>;
int headerLength = headerBytes.Sum(ab => ab.Count);
int bodyLength = bodyBytes.Sum(ab => ab.Count);
var bytes = new List<ArraySegment<byte>>();
bytes.Add(new ArraySegment<byte>(BitConverter.GetBytes(headerLength)));
bytes.Add(new ArraySegment<byte>(BitConverter.GetBytes(bodyLength)));
bytes.AddRange(headerBytes);
bytes.AddRange(bodyBytes);
if (headerLength + bodyLength > LargeMessageSizeThreshold)
{
logger.Info(ErrorCode.Messaging_LargeMsg_Outgoing, "Preparing to send large message Size={0} HeaderLength={1} BodyLength={2} #ArraySegments={3}. Msg={4}",
headerLength + bodyLength + LENGTH_HEADER_SIZE, headerLength, bodyLength, bytes.Count, this.ToString());
if (logger.IsVerbose3) logger.Verbose3("Sending large message {0}", this.ToLongString());
}
headerLengthOut = headerLength;
bodyLengthOut = bodyLength;
return bytes;
}
示例4: RoundTripGrainReferenceOrleansSerializer
private GrainReference RoundTripGrainReferenceOrleansSerializer(GrainReference input)
{
BinaryTokenStreamWriter writer = new BinaryTokenStreamWriter();
GrainReference.SerializeGrainReference(input, writer, typeof(GrainReference));
BinaryTokenStreamReader reader = new BinaryTokenStreamReader(writer.ToBytes());
GrainReference output = (GrainReference)GrainReference.DeserializeGrainReference(typeof(GrainReference), reader);
return output;
}