本文整理汇总了C#中ProtoWriter类的典型用法代码示例。如果您正苦于以下问题:C# ProtoWriter类的具体用法?C# ProtoWriter怎么用?C# ProtoWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProtoWriter类属于命名空间,在下文中一共展示了ProtoWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
public override void Write(object value, ProtoWriter dest)
{
if(getSpecified == null || (bool)getSpecified.Invoke(value, null))
{
Tail.Write(value, dest);
}
}
示例2: GenerateTypeSerializer
public void GenerateTypeSerializer()
{
var head = new TypeSerializer(typeof(CustomerStruct),
new int[] { 1, 2 },
new IProtoSerializer[] {
new PropertyDecorator(typeof(CustomerStruct), typeof(CustomerStruct).GetProperty("Id"), new TagDecorator(1, WireType.Variant,false, new Int32Serializer())),
new FieldDecorator(typeof(CustomerStruct), typeof(CustomerStruct).GetField("Name"), new TagDecorator(2, WireType.String,false, new StringSerializer()))
}, null, false, true, null, null, null);
var ser = CompilerContext.BuildSerializer(head);
var deser = CompilerContext.BuildDeserializer(head);
CustomerStruct cs1 = new CustomerStruct { Id = 123, Name = "Fred" };
using (MemoryStream ms = new MemoryStream())
{
using (ProtoWriter writer = new ProtoWriter(ms, null, null))
{
ser(cs1, writer);
}
byte[] blob = ms.ToArray();
ms.Position = 0;
using (ProtoReader reader = new ProtoReader(ms, null, null))
{
CustomerStruct? cst = (CustomerStruct?)deser(null, reader);
Assert.IsTrue(cst.HasValue);
CustomerStruct cs2 = cst.Value;
Assert.AreEqual(cs1.Id, cs2.Id);
Assert.AreEqual(cs1.Name, cs2.Name);
}
}
}
示例3: Writer
public void Writer(ProtoWriter writer, object instance)
{
switch (this.typeCode)
{
case TypeCode.Byte:
writer.Write((uint)(byte)instance);
break;
case TypeCode.SByte:
writer.Write((uint)(sbyte)instance);
break;
case TypeCode.Int16:
writer.Write((uint)(short)instance);
break;
case TypeCode.Int32:
writer.Write((uint)(int)instance);
break;
case TypeCode.UInt16:
writer.Write((uint)(ushort)instance);
break;
case TypeCode.UInt32:
writer.Write((uint)instance);
break;
case TypeCode.Int64:
writer.Write((ulong)(long)instance);
break;
case TypeCode.UInt64:
writer.Write((ulong)instance);
break;
}
}
示例4: Write
public override void Write(object value, ProtoWriter dest)
{
Helpers.DebugAssert(value != null);
value = field.GetValue(value);
//if (value!=null) Tail.Write(value, dest);
if (!Helpers.IsDefault(value)) Tail.Write(value, dest);
}
示例5: RowWriter
public RowWriter(
ProtoWriter writer,
IEnumerable<ProtoDataColumn> columns,
ProtoDataWriterOptions options)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
if (columns == null)
{
throw new ArgumentNullException("columns");
}
if (options == null)
{
throw new ArgumentNullException("options");
}
this.writer = writer;
this.columns = columns;
this.options = options;
rowIndex = 0;
}
示例6: Write
public override void Write(object value, ProtoWriter dest)
{
if (!object.Equals(value, defaultValue))
{
Tail.Write(value, dest);
}
}
示例7: Write
public void Write(object value, ProtoWriter dest)
{
for(int i = 0 ; i < tails.Length ; i++)
{
object val = GetValue(value, i);
if(val != null) tails[i].Write(val, dest);
}
}
示例8: Write
public override void Write(object value, ProtoWriter dest)
{
value = this.field.GetValue(value);
if (value != null)
{
this.Tail.Write(value, dest);
}
}
示例9: HeaderWriter
public HeaderWriter(ProtoWriter writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
this.writer = writer;
}
示例10:
void IProtoSerializer.Write(object value, ProtoWriter dest)
{
if (recursionCheck)
{
ProtoWriter.WriteObject(value, key, dest);
}
else
{
ProtoWriter.WriteRecursionSafeObject(value, key, dest);
}
}
示例11: Writer
public void Writer(ProtoWriter writer, object instance)
{
if (instance == null)
{
writer.WriteNull();
}
else
{
int messageId = writer.BeginSubMessage();
this.itemSerializer.Writer(writer, instance);
writer.EndSubMessage(messageId);
}
}
示例12: Write
public void Write(object value, ProtoWriter dest)
{
if (map == null)
{
ProtoWriter.WriteInt32(EnumToWire(value), dest);
}
else
{
for (int i = 0; i < map.Length; i++) {
if (object.Equals(map[i].Value, value)) {
ProtoWriter.WriteInt32(map[i].WireValue, dest);
return;
}
}
ProtoWriter.ThrowEnumException(dest, value);
}
}
示例13: WriteObjectContent
/// <summary>
/// Writes the body of an object in the output
/// </summary>
public override void WriteObjectContent(System.Xml.XmlDictionaryWriter writer, object graph)
{
if (graph == null)
{
writer.WriteAttributeString("nil", "true");
}
else
{
using (MemoryStream ms = new MemoryStream())
{
using (ProtoWriter protoWriter = new ProtoWriter(ms, model, null))
{
model.Serialize(key, graph, protoWriter);
}
byte[] buffer = ms.GetBuffer();
writer.WriteBase64(buffer, 0, (int)ms.Length);
}
}
}
示例14: Writer
public void Writer(ProtoWriter writer, object instance)
{
IEnumerable enumerable = (IEnumerable)instance;
int messageId = writer.BeginSubMessage();
foreach (var e in enumerable)
{
if (e == null)
{
writer.SetFieldNumber(1);
writer.WriteNull();
}
else
{
writer.SetFieldNumber(1);
this.typeDescription.NestedMessageSerializer.Writer(writer, e);
}
}
writer.EndSubMessage(messageId);
}
示例15: Write
public void Write(object value, ProtoWriter dest)
{
BclHelpers.WriteDecimal((decimal)value, dest);
}