当前位置: 首页>>代码示例>>C#>>正文


C# ProtoReader.ReadFieldHeader方法代码示例

本文整理汇总了C#中ProtoReader.ReadFieldHeader方法的典型用法代码示例。如果您正苦于以下问题:C# ProtoReader.ReadFieldHeader方法的具体用法?C# ProtoReader.ReadFieldHeader怎么用?C# ProtoReader.ReadFieldHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProtoReader的用法示例。


在下文中一共展示了ProtoReader.ReadFieldHeader方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: Read

 public object Read(object value, ProtoReader source)
 {
     object[] values = new object[members.Length];
     bool invokeCtor = false;
     if (value == null)
     {
         invokeCtor = true;
     }
     for (int i = 0; i < values.Length; i++)
         values[i] = GetValue(value, i);
     int field;
     while ((field = source.ReadFieldHeader()) > 0)
     {
         invokeCtor = true;
         if (field <= tails.Length)
         {
             IProtoSerializer tail = tails[field - 1];
             values[field - 1] = tails[field - 1].Read(tail.RequiresOldValue ? values[field - 1] : null, source);
         }
         else
         {
             source.SkipField();
         }
     }
     return invokeCtor ? ctor.Invoke(values) : value;
 }
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:26,代码来源:TupleSerializer.cs

示例3: Read

 public override object Read(object value, ProtoReader source)
 {
     SubItemToken tok = ProtoReader.StartSubItem(source);
     int field;
     while((field = source.ReadFieldHeader()) > 0)
     {
         if(field == Tag) {
             value = Tail.Read(value, source);
         } else {
             source.SkipField();
         }
     }
     ProtoReader.EndSubItem(tok, source);
     return value;
 }
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:15,代码来源:NullDecorator.cs

示例4: Read

 public object Read(object value, ProtoReader source)
 {
     object[] array = new object[this.members.Length];
     bool flag = false;
     if (value == null)
     {
         flag = true;
     }
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = this.GetValue(value, i);
     }
     int num;
     while ((num = source.ReadFieldHeader()) > 0)
     {
         flag = true;
         if (num <= this.tails.Length)
         {
             IProtoSerializer protoSerializer = this.tails[num - 1];
             array[num - 1] = this.tails[num - 1].Read((!protoSerializer.RequiresOldValue) ? null : array[num - 1], source);
         }
         else
         {
             source.SkipField();
         }
     }
     return (!flag) ? value : this.ctor.Invoke(array);
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:28,代码来源:TupleSerializer.cs

示例5: Read

        public override object Read(object value, ProtoReader source)
        {
			if (nested)
			{
				source.ReadFieldHeader();
			}

            int field = source.FieldNumber;
            BasicList list = new BasicList();

			if (packedWireType != WireType.None && source.WireType == WireType.String)
            {
                SubItemToken token = ProtoReader.StartSubItem(source);
                while (ProtoReader.HasSubValue(packedWireType, source))
                {
                    list.Add(Tail.Read(null, source));
                }
                ProtoReader.EndSubItem(token, source);

				int oldLen = AppendToCollection ? ((value == null ? 0 : ((Array)value).Length)) : 0;
				Array result = Array.CreateInstance(itemType, oldLen + list.Count);
				if (oldLen != 0) ((Array)value).CopyTo(result, 0);
				list.CopyTo(result, oldLen);

            	return result;
            }
            else
            {
				bool readObject = true;
            	int arrayKey = 0;

				value = value ?? Array.CreateInstance(itemType, 0);

				if (AsReference)
            	{
					int objectKey = source.ReadInt32();

					if (objectKey > 0)
					{
						value = source.NetCache.GetKeyedObject(objectKey);
						readObject = false;
					}
					else
					{
						bool dummy;
						arrayKey = source.NetCache.AddObjectKey(value, out dummy);
					}
            	}
				else
				{
					bool isEmpty = source.ReadInt32() == 1;
					if (isEmpty)
					{
						return value; 
					}
				}

				if (readObject)
				{
					while (source.TryReadFieldHeader(field)) 
					{
						list.Add(Tail.Read(null, source));
					}

					Array newArray = Array.CreateInstance(itemType, list.Count);
					list.CopyTo(newArray, 0);

					if (AsReference)
					{
						source.NetCache.UpdateKeyedObject(arrayKey, value, newArray);	
					}

					value = newArray;
				}
            }

            return value;
        }
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:78,代码来源:ArrayDecorator.cs

示例6: Read

        public object Read(object value, ProtoReader source)
        {
            if (isRootType && value != null) { Callback(value, TypeModel.CallbackType.BeforeDeserialize, source.Context); }
            int fieldNumber, lastFieldNumber = 0, lastFieldIndex = 0;
            bool fieldHandled;

            //Helpers.DebugWriteLine(">> Reading fields for " + forType.FullName);
            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                fieldHandled = false;
                if (fieldNumber < lastFieldNumber)
                {
                    lastFieldNumber = lastFieldIndex = 0;
                }
                for (int i = lastFieldIndex; i < fieldNumbers.Length; i++)
                {
                    if (fieldNumbers[i] == fieldNumber)
                    {
                        IProtoSerializer ser = serializers[i];
                        //Helpers.DebugWriteLine(": " + ser.ToString());
                        if (value == null && ser.ExpectedType == forType) value = CreateInstance(source);
                        if (ser.ReturnsValue) {
                            value = ser.Read(value, source);
                        } else { // pop
                            ser.Read(value, source);
                        }

                        lastFieldIndex = i;
                        lastFieldNumber = fieldNumber;
                        fieldHandled = true;
                        break;
                    }
                }
                if (!fieldHandled)
                {
                    //Helpers.DebugWriteLine(": [" + fieldNumber + "] (unknown)");
                    if (value == null) value = CreateInstance(source);
                    if (isExtensible) {
                        source.AppendExtensionData((IExtensible)value);
                    } else {
                        source.SkipField();
                    }
                }
            }
            //Helpers.DebugWriteLine("<< Reading fields for " + forType.FullName);
            if(value == null) value = CreateInstance(source);
            if (isRootType) { Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context); }
            return value;
        }
开发者ID:helios57,项目名称:anrl,代码行数:49,代码来源:TypeSerializer.cs

示例7: TryDeserializeAuxiliaryType

        /// <summary>
        /// This is the more "complete" version of Deserialize, which handles single instances of mapped types.
        /// The value is read as a complete field, including field-header and (for sub-objects) a
        /// length-prefix..kmc  
        /// 
        /// In addition to that, this provides support for:
        ///  - basic values; individual int / string / Guid / etc
        ///  - IList sets of any type handled by TryDeserializeAuxiliaryType
        /// </summary>
        private bool TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, int tag, Type type, ref object value, bool skipOtherFields, bool asListItem)
        {
            if (type == null) throw new ArgumentNullException("type");
            Type itemType = null;
            TypeCode typecode = Type.GetTypeCode(type);
            int modelKey;
            WireType wiretype = GetWireType(typecode, format, ref type, out modelKey);

            bool found = false;
            if (wiretype == WireType.None)
            {
                itemType = GetListItemType(type);

                if (itemType != null)
                {
                    return TryDeserializeList(reader, format, tag, type, itemType, ref value);                    
                }
                // otherwise, not a happy bunny...
                ThrowUnexpectedType(type);
            }
            
            // to treat correctly, should read all values

            while (true)
            {
                // for convenience (re complex exit conditions), additional exit test here:
                // if we've got the value, are only looking for one, and we aren't a list - then exit
                if (found && asListItem) break;

                // read the next item
                int fieldNumber = reader.ReadFieldHeader();
                if (fieldNumber <= 0) break;
                if (fieldNumber != tag)
                {
                    if (skipOtherFields)
                    {
                        reader.SkipField();
                        continue;
                    }
                    throw ProtoReader.AddErrorData(new InvalidOperationException(
                        "Expected field " + tag + ", but found " + fieldNumber), reader);
                }
                found = true;
                reader.Hint(wiretype); // handle signed data etc

                if (modelKey >= 0)
                {
                    switch (wiretype)
                    {
                        case WireType.String:
                        case WireType.StartGroup:
                            SubItemToken token = ProtoReader.StartSubItem(reader);
                            value = Deserialize(modelKey, value, reader);
                            ProtoReader.EndSubItem(token, reader);
                            continue;
                        default:
                            value = Deserialize(modelKey, value, reader);
                            continue;
                    }
                }
                switch (typecode)
                {
                    case TypeCode.Int16: value = reader.ReadInt16(); continue;
                    case TypeCode.Int32: value = reader.ReadInt32(); continue;
                    case TypeCode.Int64: value = reader.ReadInt64(); continue;
                    case TypeCode.UInt16: value = reader.ReadUInt16(); continue;
                    case TypeCode.UInt32: value = reader.ReadUInt32(); continue;
                    case TypeCode.UInt64: value = reader.ReadUInt64(); continue;
                    case TypeCode.Boolean: value = reader.ReadBoolean(); continue;
                    case TypeCode.SByte: value = reader.ReadSByte(); continue;
                    case TypeCode.Byte: value = reader.ReadByte(); continue;
                    case TypeCode.Char: value = (char)reader.ReadUInt16(); continue;
                    case TypeCode.Double: value = reader.ReadDouble(); continue;
                    case TypeCode.Single: value = reader.ReadSingle(); continue;
                    case TypeCode.DateTime: value = BclHelpers.ReadDateTime(reader); continue;
                    case TypeCode.Decimal: BclHelpers.ReadDecimal(reader); continue;
                    case TypeCode.String: value = reader.ReadString(); continue;
                }
                if (type == typeof(byte[])) { value = ProtoReader.AppendBytes((byte[])value, reader); continue; }
                if (type == typeof(TimeSpan)) { value = BclHelpers.ReadTimeSpan(reader); continue; }
                if (type == typeof(Guid)) { value = BclHelpers.ReadGuid(reader); continue; }
                if (type == typeof(Uri)) { value = new Uri(reader.ReadString()); continue; }

            }
            if (!found && !asListItem) { value = Activator.CreateInstance(type); }
            return found;
        }
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:96,代码来源:TypeModel.cs

示例8: Read

        public object Read(object value, ProtoReader source)
        {
			object[] values = new object[members.Length];
        	int tupleKey = 0;
        	object oldTuple = null;

        	bool issueReferenceDirectives = !baseTupleAsReference && asReference;

        	if (issueReferenceDirectives)
			{
				tupleKey = (int)source.ReadUInt32();

				if (tupleKey > 0)
				{
					return source.NetCache.GetKeyedObject(tupleKey);
				}
				else
				{
					bool dummy;
					oldTuple = new object();

					tupleKey = source.NetCache.AddObjectKey(oldTuple, out dummy);
				}
			}

			bool invokeCtor = false;
			if (value == null)
			{
				invokeCtor = true;
			}
			for (int i = 0; i < values.Length; i++)
				values[i] = GetValue(value, i);

        	int j = 0;
			
        	int field;
			while (j++ < values.Length && source.ReadNextFieldHack() > 0)
			{
				field = source.ReadFieldHeader();

				invokeCtor = true;
                if(field <= tails.Length)
                {
                    IProtoSerializer tail = tails[field - 1];
                    values[field - 1] = tails[field - 1].Read(tail.RequiresOldValue ? values[field - 1] : null, source);
                }
                else
                {
                    source.SkipField();
                }
            }

        	object result = invokeCtor ? ctor.Invoke(values) : value;

			if (issueReferenceDirectives)
			{
				source.NetCache.UpdateKeyedObject(tupleKey, oldTuple, result);
			}

			if (forceIssueFakeHeader)
			{
				source.ReadEndGroupFieldHeaderHack();
			}

        	return result;
        }
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:66,代码来源:TupleSerializer.cs

示例9: Read

 public object Read(object value, ProtoReader source)
 {
     if (this.isRootType && value != null)
     {
         this.Callback(value, TypeModel.CallbackType.BeforeDeserialize, source.Context);
     }
     int num = 0;
     int num2 = 0;
     int num3;
     while ((num3 = source.ReadFieldHeader()) > 0)
     {
         bool flag = false;
         if (num3 < num)
         {
             num2 = (num = 0);
         }
         for (int i = num2; i < this.fieldNumbers.Length; i++)
         {
             if (this.fieldNumbers[i] == num3)
             {
                 IProtoSerializer protoSerializer = this.serializers[i];
                 Type expectedType = protoSerializer.ExpectedType;
                 if (value == null)
                 {
                     if (expectedType == this.forType)
                     {
                         value = this.CreateInstance(source, true);
                     }
                 }
                 else if (expectedType != this.forType && ((IProtoTypeSerializer)protoSerializer).CanCreateInstance() && expectedType.IsSubclassOf(value.GetType()))
                 {
                     value = ProtoReader.Merge(source, value, ((IProtoTypeSerializer)protoSerializer).CreateInstance(source));
                 }
                 if (protoSerializer.ReturnsValue)
                 {
                     value = protoSerializer.Read(value, source);
                 }
                 else
                 {
                     protoSerializer.Read(value, source);
                 }
                 num2 = i;
                 num = num3;
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             if (value == null)
             {
                 value = this.CreateInstance(source, true);
             }
             if (this.isExtensible)
             {
                 source.AppendExtensionData((IExtensible)value);
             }
             else
             {
                 source.SkipField();
             }
         }
     }
     if (value == null)
     {
         value = this.CreateInstance(source, true);
     }
     if (this.isRootType)
     {
         this.Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context);
     }
     return value;
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:73,代码来源:TypeSerializer.cs


注:本文中的ProtoReader.ReadFieldHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。