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


C# ProtoReader.ReadInt32方法代码示例

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


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

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

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

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

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

示例5: Read

 public object Read(object value, ProtoReader source)
 {
     Helpers.DebugAssert(value == null); // since replaces
     return source.ReadInt32();
 }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:5,代码来源:Int32Serializer.cs

示例6: Read

 public object Read(object value, ProtoReader source)
 {
     return source.ReadInt32();
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:4,代码来源:Int32Serializer.cs


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