本文整理汇总了C#中Orleans.Serialization.BinaryTokenStreamWriter.Write方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryTokenStreamWriter.Write方法的具体用法?C# BinaryTokenStreamWriter.Write怎么用?C# BinaryTokenStreamWriter.Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orleans.Serialization.BinaryTokenStreamWriter
的用法示例。
在下文中一共展示了BinaryTokenStreamWriter.Write方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public void Serialize(object item, BinaryTokenStreamWriter writer, Type expectedType)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
if (item == null)
{
writer.WriteNull();
return;
}
var formatter = new BinaryFormatter();
byte[] bytes;
using (var memoryStream = new MemoryStream())
{
formatter.Serialize(memoryStream, item);
memoryStream.Flush();
bytes = memoryStream.ToArray();
}
writer.Write(bytes.Length);
writer.Write(bytes);
}
示例2: Serialize
private static void Serialize(object input, BinaryTokenStreamWriter stream, Type expected)
{
SerializeCounter++;
var obj = input as ClassWithCustomSerializer;
stream.Write(obj.IntProperty);
stream.Write(obj.StringProperty);
}
示例3: Serialize
/// <summary>
/// Serialize the event sequence token.
/// </summary>
/// <param name="untypedInput">The object to serialize.</param>
/// <param name="writer">The writer to write the binary stream to.</param>
/// <param name="expected">The expected type.</param>
public static void Serialize(object untypedInput, BinaryTokenStreamWriter writer, Type expected)
{
var typed = untypedInput as EventSequenceTokenV2;
if (typed == null)
{
writer.WriteNull();
return;
}
writer.Write(typed.SequenceNumber);
writer.Write(typed.EventIndex);
}
示例4: Serialize
internal static void Serialize(object obj, BinaryTokenStreamWriter stream, Type unused)
{
var envelope = (ResponseEnvelope)obj;
if (envelope.Result == null)
{
stream.Write(ResultToken.Null);
return;
}
stream.Write(ResultToken.Some);
MessageEnvelope.Serializer.Serialize(envelope.Result, stream);
}
示例5: 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).");
}
}
示例6: Serialize
/// <summary>
/// Serializes an object to a binary stream
/// </summary>
/// <param name="item">The object to serialize</param>
/// <param name="writer">The <see cref="BinaryTokenStreamWriter"/></param>
/// <param name="expectedType">The type the deserializer should expect</param>
public void Serialize(object item, BinaryTokenStreamWriter writer, Type expectedType)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
if (item == null)
{
// Special handling for null value.
// Since in this ProtobufSerializer we are usualy writing the data lengh as 4 bytes
// we also have to write the Null object as 4 bytes lengh of zero.
writer.Write(0);
return;
}
IMessage iMessage = item as IMessage;
if (iMessage == null)
{
throw new ArgumentException("The provided item for serialization in not an instance of " + typeof(IMessage), "item");
}
// The way we write the data is potentially in-efficinet,
// since we are first writing to ProtoBuff's internal CodedOutputStream
// and then take its internal byte[] and write it into out own BinaryTokenStreamWriter.
// Writing byte[] to BinaryTokenStreamWriter may sometimes copy the byte[] and sometimes just append ass ArraySegment without copy.
// In the former case it will be a secodnd copy.
// It would be more effecient to write directly into BinaryTokenStreamWriter
// but protobuff does not currently support writing directly into a given arbitary stream
// (it does support System.IO.Steam but BinaryTokenStreamWriter is not compatible with System.IO.Steam).
// Alternatively, we could force to always append to BinaryTokenStreamWriter, but that could create a lot of small ArraySegments.
// The plan is to ask the ProtoBuff team to add support for some "InputStream" interface, like Bond does.
byte[] outBytes = iMessage.ToByteArray();
writer.Write(outBytes.Length);
writer.Write(outBytes);
}
示例7: WriteType
private void WriteType(Type actualType, Type expectedType, BinaryTokenStreamWriter writer)
{
if (actualType == expectedType)
{
writer.Write((byte)SerializationTokenType.ExpectedType);
}
else
{
writer.Write((byte)SerializationTokenType.NamedType);
writer.Write(actualType.AssemblyQualifiedName);
}
}
示例8: Serialize
/// <summary>
/// Serializes an object to a binary stream
/// </summary>
/// <param name="item">The object to serialize</param>
/// <param name="writer">The <see cref="BinaryTokenStreamWriter"/></param>
/// <param name="expectedType">The type the deserializer should expect</param>
public void Serialize(object item, BinaryTokenStreamWriter writer, Type expectedType)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
if (item == null)
{
writer.WriteNull();
return;
}
var str = JsonConvert.SerializeObject(item, expectedType, defaultSettings);
writer.Write(str);
}
示例9: Serializer
public static void Serializer(object untypedInput, BinaryTokenStreamWriter stream, Type expected)
{
byte[] buffer = Serialize(untypedInput);
stream.Write(buffer.Length);
stream.Write(buffer);
}
示例10: Serializer
public static void Serializer(System.Object untypedInput, BinaryTokenStreamWriter stream, System.Type expected)
{
HeadersContainer input = (HeadersContainer)untypedInput;
var headers = input.GetHeadersMask();
stream.Write((int)headers);
if ((headers & Headers.CACHE_INVALIDATION_HEADER) != Headers.NONE)
{
var count = input.CacheInvalidationHeader.Count;
stream.Write(input.CacheInvalidationHeader.Count);
for (int i = 0; i < count; i++)
{
WriteObj(stream, typeof(ActivationAddress), input.CacheInvalidationHeader[i]);
}
}
if ((headers & Headers.CATEGORY) != Headers.NONE)
{
stream.Write((byte)input.Category);
}
if ((headers & Headers.DEBUG_CONTEXT) != Headers.NONE)
stream.Write(input.DebugContext);
if ((headers & Headers.DIRECTION) != Headers.NONE)
stream.Write((byte)input.Direction.Value);
if ((headers & Headers.EXPIRATION) != Headers.NONE)
stream.Write(input.Expiration.Value);
if ((headers & Headers.FORWARD_COUNT) != Headers.NONE)
stream.Write(input.ForwardCount);
if ((headers & Headers.GENERIC_GRAIN_TYPE) != Headers.NONE)
stream.Write(input.GenericGrainType);
if ((headers & Headers.CORRELATION_ID) != Headers.NONE)
stream.Write(input.Id);
if ((headers & Headers.ALWAYS_INTERLEAVE) != Headers.NONE)
stream.Write(input.IsAlwaysInterleave);
if ((headers & Headers.IS_NEW_PLACEMENT) != Headers.NONE)
stream.Write(input.IsNewPlacement);
if ((headers & Headers.READ_ONLY) != Headers.NONE)
stream.Write(input.IsReadOnly);
if ((headers & Headers.IS_UNORDERED) != Headers.NONE)
stream.Write(input.IsUnordered);
if ((headers & Headers.NEW_GRAIN_TYPE) != Headers.NONE)
stream.Write(input.NewGrainType);
if ((headers & Headers.REJECTION_INFO) != Headers.NONE)
stream.Write(input.RejectionInfo);
if ((headers & Headers.REJECTION_TYPE) != Headers.NONE)
stream.Write((byte)input.RejectionType);
if ((headers & Headers.REQUEST_CONTEXT) != Headers.NONE)
{
var requestData = input.RequestContextData;
var count = requestData.Count;
stream.Write(count);
foreach (var d in requestData)
{
stream.Write(d.Key);
SerializationManager.SerializeInner(d.Value, stream, typeof(object));
}
}
if ((headers & Headers.RESEND_COUNT) != Headers.NONE)
stream.Write(input.ResendCount);
if ((headers & Headers.RESULT) != Headers.NONE)
stream.Write((byte)input.Result);
if ((headers & Headers.SENDING_ACTIVATION) != Headers.NONE)
{
stream.Write(input.SendingActivation);
}
if ((headers & Headers.SENDING_GRAIN) != Headers.NONE)
{
stream.Write(input.SendingGrain);
}
if ((headers & Headers.SENDING_SILO) != Headers.NONE)
{
stream.Write(input.SendingSilo);
}
if ((headers & Headers.TARGET_ACTIVATION) != Headers.NONE)
{
stream.Write(input.TargetActivation);
}
if ((headers & Headers.TARGET_GRAIN) != Headers.NONE)
{
stream.Write(input.TargetGrain);
//.........这里部分代码省略.........
示例11: SerializeGrainCancellationToken
internal static void SerializeGrainCancellationToken(object obj, BinaryTokenStreamWriter stream, Type expected)
{
var ctw = (GrainCancellationToken)obj;
var canceled = ctw.CancellationToken.IsCancellationRequested;
stream.Write(canceled);
stream.Write(ctw.Id);
}
示例12: Serialize
internal static void Serialize(object obj, BinaryTokenStreamWriter stream, Type unused)
{
var envelope = (RequestEnvelope) obj;
stream.Write(envelope.Target);
MessageEnvelope.Serializer.Serialize(envelope.Message, stream);
}
示例13: Serialize
public void Serialize(object item, BinaryTokenStreamWriter writer, Type expectedType)
{
var typed = (SimpleType)item;
writer.Write(typed.Number);
}