本文整理汇总了C#中ProtoReader类的典型用法代码示例。如果您正苦于以下问题:C# ProtoReader类的具体用法?C# ProtoReader怎么用?C# ProtoReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProtoReader类属于命名空间,在下文中一共展示了ProtoReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public override object Read(object value, ProtoReader source)
{
Helpers.DebugAssert(value != null);
object newValue = Tail.Read((Tail.RequiresOldValue ? field.GetValue(value) : null), source);
if(newValue != null) field.SetValue(value,newValue);
return null;
}
示例2: Read
//TODO: TimeZone
public object Read(ProtoReader reader)
{
long ticks = 0;
int offset = 0;
byte[] buffer = reader.ReadByteArray();
ticks |= (long)buffer[offset++];
ticks |= (long)buffer[offset++] << 8;
ticks |= (long)buffer[offset++] << 16;
ticks |= (long)buffer[offset++] << 24;
ticks |= (long)buffer[offset++] << 32;
ticks |= (long)buffer[offset++] << 40;
ticks |= (long)buffer[offset++] << 48;
ticks |= (long)buffer[offset++] << 56;
DateTimeKind kind = (DateTimeKind)buffer[offset++];
if (kind == DateTimeKind.Local)
{
return new DateTime(ticks, DateTimeKind.Utc).ToLocalTime();
}
return new DateTime(ticks, kind);
}
示例3: Read
public override object Read(object value, ProtoReader source)
{
Helpers.DebugAssert(fieldNumber == source.FieldNumber);
if (strict) { source.Assert(wireType); }
else if (NeedsHint) { source.Hint(wireType); }
return Tail.Read(value, source);
}
示例4: Read
public override object Read(object value, ProtoReader source)
{
Helpers.DebugAssert(value == null); // not expecting incoming
string s = (string)Tail.Read(null, source);
return s.Length == 0 ? null : typeConstructor.Invoke(new object[] { s });
}
示例5: 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);
}
}
}
示例6: Read
public object Read(object value, ProtoReader source)
{
return this.parse.Invoke(null, new object[]
{
source.ReadString()
});
}
示例7: Read
public object Read(ProtoReader reader)
{
IList list = (isArray ? new ArrayList() : (IList)Activator.CreateInstance(listType));
int fieldNumber;
int messageSize = reader.BeginSubMessage();
while ((fieldNumber = reader.ReadTag()) > 0)
{
object value;
if (reader.WireType == WireType.Null)
{
value = reader.ReadNull();
}
else
{
value = this.typeDescription.NestedMessageSerializer.Read(reader);
}
list.Add(value);
}
reader.EndSubMessage(messageSize);
if (isArray)
{
int length = list.Count;
Array array = Array.CreateInstance(elementType, length);
list.CopyTo(array, 0);
return array;
}
return list;
}
示例8: Read
public override object Read(object value, ProtoReader source)
{
object obj = this.Tail.Read((!this.Tail.RequiresOldValue) ? null : this.field.GetValue(value), source);
if (obj != null)
{
this.field.SetValue(value, obj);
}
return null;
}
示例9: Read
public object Read(object value, ProtoReader source)
{
// convert the incoming value
object[] args = { value };
value = toTail.Invoke(null, args);
// invoke the tail and convert the outgoing value
args[0] = rootTail.Read(value, source);
return fromTail.Invoke(null, args);
}
示例10: Read
public object Read(ProtoReader reader)
{
int fn = reader.ReadTag();
if (fn == 0)
{
throw new InvalidProgramException();
}
return this.itemSerializer.Read(reader);
}
示例11: Read
public override object Read(object value, ProtoReader source)
{
object result = this.Tail.Read(value, source);
if (this.setSpecified != null)
{
this.setSpecified.Invoke(value, new object[]
{
true
});
}
return result;
}
示例12: Read
public override object Read(object value, ProtoReader source)
{
Helpers.DebugAssert(value != null);
object oldVal = Tail.RequiresOldValue ? property.GetValue(value, null) : null;
object newVal = Tail.Read(oldVal, source);
if (readOptionsWriteValue)
{
property.SetValue(value, newVal, null);
}
return null;
}
示例13: ProtoDataReader
/// <summary>
/// Initializes a new instance of a <see cref="ProtoBuf.Data.ProtoDataReader"/> type.
/// </summary>
/// <param name="stream">The <see cref="System.IO.Stream"/> to read from.</param>
public ProtoDataReader(Stream stream)
{
if (stream == null) throw new ArgumentNullException("stream");
this.stream = stream;
reader = new ProtoReader(stream, null, null);
colReaders = new List<ColReader>();
AdvanceToNextField();
if (currentField != 1)
throw new InvalidOperationException("No results found! Invalid/corrupt stream.");
ReadNextTableHeader();
}
示例14: Read
public object Read(ProtoReader reader)
{
if (reader.WireType == WireType.Null)
{
return reader.ReadNull();
}
object value = null;
int messageSize = reader.BeginSubMessage();
value = this.itemSerializer.Read(reader);
reader.EndSubMessage(messageSize);
return value;
}
示例15: Read
public object Read(object value, ProtoReader source)
{
Helpers.DebugAssert(value == null); // since replaces
int wireValue = source.ReadInt32();
if(map == null) {
return WireToEnum(wireValue);
}
for(int i = 0 ; i < map.Length ; i++) {
if(map[i].WireValue == wireValue) {
return map[i].Value;
}
}
source.ThrowEnumException(ExpectedType, wireValue);
return null; // to make compiler happy
}