本文整理汇总了C#中ProtoReader类的典型用法代码示例。如果您正苦于以下问题:C# ProtoReader类的具体用法?C# ProtoReader怎么用?C# ProtoReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProtoReader类属于命名空间,在下文中一共展示了ProtoReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:helios57,项目名称:anrl,代码行数:7,代码来源:FieldDecorator.cs
示例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);
}
开发者ID:,项目名称:,代码行数:26,代码来源:
示例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);
}
开发者ID:tsuixl,项目名称:Frame,代码行数:7,代码来源:TagDecorator.cs
示例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 });
}
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:7,代码来源:ReflectedUriDecorator.cs
示例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);
}
}
}
开发者ID:Ribosome2,项目名称:protobuf-net-1,代码行数:29,代码来源:Struct.cs
示例6: Read
public object Read(object value, ProtoReader source)
{
return this.parse.Invoke(null, new object[]
{
source.ReadString()
});
}
开发者ID:floatyears,项目名称:Decrypt,代码行数:7,代码来源:ParseableSerializer.cs
示例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;
}
开发者ID:robb83,项目名称:Protocols,代码行数:35,代码来源:ListSerializer.cs
示例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;
}
开发者ID:floatyears,项目名称:Decrypt,代码行数:9,代码来源:FieldDecorator.cs
示例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);
}
开发者ID:techtronics,项目名称:mapreduce-net,代码行数:10,代码来源:SurrogateSerializer.cs
示例10: Read
public object Read(ProtoReader reader)
{
int fn = reader.ReadTag();
if (fn == 0)
{
throw new InvalidProgramException();
}
return this.itemSerializer.Read(reader);
}
开发者ID:robb83,项目名称:Protocols,代码行数:11,代码来源:PrimitivesDecorator.cs
示例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;
}
开发者ID:floatyears,项目名称:Decrypt,代码行数:12,代码来源:MemberSpecifiedDecorator.cs
示例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;
}
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:12,代码来源:PropertyDecorator.cs
示例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();
}
开发者ID:RFQ-hub,项目名称:protobuf-net-data,代码行数:19,代码来源:ProtoDataReader.cs
示例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;
}
开发者ID:robb83,项目名称:Protocols,代码行数:15,代码来源:TypeDecorator.cs
示例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
}
开发者ID:helios57,项目名称:anrl,代码行数:15,代码来源:EnumSerializer.cs
示例16: Read
public object Read(ProtoReader reader)
{
object instance = Activator.CreateInstance(objectType);
int fn;
while((fn = reader.ReadTag()) > 0)
{
IMemberSerializer serializer = GetSerializerByFieldNumber(fn);
if (serializer == null)
continue;
serializer.Read(reader, instance);
}
return instance;
}
开发者ID:robb83,项目名称:Protocols,代码行数:17,代码来源:TypeSerializer.cs
示例17: Read
public object Read(object value, ProtoReader source)
{
int num = source.ReadInt32();
if (this.map == null)
{
return this.WireToEnum(num);
}
for (int i = 0; i < this.map.Length; i++)
{
if (this.map[i].WireValue == num)
{
return this.map[i].TypedValue;
}
}
source.ThrowEnumException(this.ExpectedType, num);
return null;
}
开发者ID:floatyears,项目名称:Decrypt,代码行数:17,代码来源:EnumSerializer.cs
示例18: Read
public override object Read(object value, ProtoReader source)
{
SubItemToken token = ProtoReader.StartSubItem(source);
int num;
while ((num = source.ReadFieldHeader()) > 0)
{
if (num == 1)
{
value = this.Tail.Read(value, source);
}
else
{
source.SkipField();
}
}
ProtoReader.EndSubItem(token, source);
return value;
}
开发者ID:floatyears,项目名称:Decrypt,代码行数:18,代码来源:NullDecorator.cs
示例19: 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 && newVal != null) // if the tail returns a null, intepret that as *no assign*
{
if (shadowSetter == null)
{
property.SetValue(value, newVal, null);
}
else
{
shadowSetter.Invoke(value, new object[] { newVal });
}
}
return null;
}
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:19,代码来源:PropertyDecorator.cs
示例20: ReadObject
/// <summary>
/// Reads the body of an object
/// </summary>
public override object ReadObject(System.Xml.XmlDictionaryReader reader, bool verifyObjectName)
{
if (reader.GetAttribute("nil") == "true") return null;
reader.ReadStartElement(PROTO_ELEMENT);
try
{
using (MemoryStream ms = new MemoryStream(reader.ReadContentAsBase64()))
{
using (ProtoReader protoReader = new ProtoReader(ms, model, null))
{
return model.Deserialize(key, null, protoReader);
}
}
}
finally
{
reader.ReadEndElement();
}
}
开发者ID:helios57,项目名称:anrl,代码行数:22,代码来源:XmlProtoSerializer.cs
注:本文中的ProtoReader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论