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


C# ProtoReader.ReadInt32方法代码示例

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


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

示例1: ReadNetObject

        /// <summary>
        /// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
        /// </summary>
        public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
        {
#if FEAT_IKVM
            throw new NotSupportedException();
#else
            SubItemToken token = ProtoReader.StartSubItem(source);
            int fieldNumber;
            int newObjectKey = -1, newTypeKey = -1, tmp;
            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                    case FieldExistingObjectKey:
                        tmp = source.ReadInt32();
                        value = source.NetCache.GetKeyedObject(tmp);
                        break;
                    case FieldNewObjectKey:
                        newObjectKey = source.ReadInt32();
                        break;
                    case FieldExistingTypeKey:
                        tmp = source.ReadInt32();
                        type = (Type)source.NetCache.GetKeyedObject(tmp);
                        key = source.GetTypeKey(ref type);
                        break;
                    case FieldNewTypeKey:
                        newTypeKey = source.ReadInt32();
                        break;
                    case FieldTypeName:
                        string typeName = source.ReadString();
                        type = source.DeserializeType(typeName);
                        if(type == null)
                        {
                            throw new ProtoException("Unable to resolve type: " + typeName + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
                        }
                        if (type == typeof(string))
                        {
                            key = -1;
                        }
                        else
                        {
                            key = source.GetTypeKey(ref type);
                            if (key < 0)
                                throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                        }
                        break;
                    case FieldObject:
                        bool isString = type == typeof(string);
                        bool wasNull = value == null;
                        bool lateSet = wasNull && (isString || ((options & NetObjectOptions.LateSet) != 0));
                        
                        if (newObjectKey >= 0 && !lateSet)
                        {
                            if (value == null)
                            {
                                source.TrapNextObject(newObjectKey);
                            }
                            else
                            {
                                source.NetCache.SetKeyedObject(newObjectKey, value);
                            }
                            if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                        object oldValue = value;
                        if (isString)
                        {
                            value = source.ReadString();
                        }
                        else
                        {
                            value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
                        }
                        
                        if (newObjectKey >= 0)
                        {
                            if(wasNull && !lateSet)
                            { // this both ensures (via exception) that it *was* set, and makes sure we don't shout
                                // about changed references
                                oldValue = source.NetCache.GetKeyedObject(newObjectKey);
                            }
                            if (lateSet)
                            {
                                source.NetCache.SetKeyedObject(newObjectKey, value);
                                if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
                            }
                        }
                        if (newObjectKey >= 0 && !lateSet && !ReferenceEquals(oldValue, value))
                        {
                            throw new ProtoException("A reference-tracked object changed reference during deserialization");
                        }
                        if (newObjectKey < 0 && newTypeKey >= 0)
                        {  // have a new type, but not a new object
                            source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                        break;
                    default:
                        source.SkipField();
                        break;
//.........这里部分代码省略.........
开发者ID:tsuixl,项目名称:Frame,代码行数:101,代码来源:BclHelpers.cs

示例2: ReadNetObject

        /// <summary>
        /// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
        /// </summary>
        public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
        {
            SubItemToken token = ProtoReader.StartSubItem(source);
            int fieldNumber;
            int newObjectKey = -1, newTypeKey = -1, tmp;
            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                    case FieldExistingObjectKey:
                        tmp = source.ReadInt32();
                        value = source.NetCache.GetKeyedObject(tmp);
                        break;
                    case FieldNewObjectKey:
                        newObjectKey = source.ReadInt32();
                        break;
                    case FieldExistingTypeKey:
                        tmp = source.ReadInt32();
                        type = (Type)source.NetCache.GetKeyedObject(tmp);
                        key = source.GetTypeKey(ref type);
                        break;
                    case FieldNewTypeKey:
                        newTypeKey = source.ReadInt32();
                        break;
                    case FieldTypeName:
                        string typeName = source.ReadString();
                        type = source.DeserializeType(typeName);
                        if(type == null)
                        {
                            throw new ProtoException("Unable to resolve type: " + typeName + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
                        }
                        key = source.GetTypeKey(ref type);
                        if(key < 0) throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                        break;
                    case FieldObject:
                        bool isString = type == typeof(string);
                        bool lateSet = value == null && isString;
                        if (value == null && !lateSet)
                        {
                            try
                            {
                                value = ((options & NetObjectOptions.UseConstructor) == 0)
                                            ? BclHelpers.GetUninitializedObject(type)
											: (type.IsArray || type.IsInterface ? null : Activator.CreateInstance(type, true));
                            } catch (Exception ex)
                            {
                                throw new ProtoException("Unable to create type " + (type == null ? "<null>" : type.FullName) + ": " + ex.Message, ex);
                            }
                        }
                        if (newObjectKey >= 0 && !lateSet)
                        {
                            source.NetCache.SetKeyedObject(newObjectKey, value);
                            if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                        object oldValue = value;
                        if (isString)
                        {
                            value = source.ReadString();
                        }
                        else
                        {
                            value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
                        }
                        
                        if (newObjectKey >= 0 && lateSet)
                        {
                            source.NetCache.SetKeyedObject(newObjectKey, value);
                            if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
						if (newObjectKey >= 0 && !lateSet && !ReferenceEquals(oldValue, value) && type.FullName.StartsWith("System.Collections.Generic.Dictionary`2"))
                        {
                            throw new ProtoException("A reference-tracked object changed reference during deserialization");
                        }
                        if (newObjectKey < 0 && newTypeKey >= 0)
                        {  // have a new type, but not a new object
                            source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                        break;
                    default:
                        source.SkipField();
                        break;
                }
            }
            if(newObjectKey >= 0 && (options & NetObjectOptions.AsReference) == 0)
            {
                throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
            }
            ProtoReader.EndSubItem(token, source);

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

示例3: ReadTimeSpanTicks

 private static long ReadTimeSpanTicks(ProtoReader source) {
     switch (source.WireType)
     {
         case WireType.String:
         case WireType.StartGroup:
             SubItemToken token = ProtoReader.StartSubItem(source);
             int fieldNumber;
             TimeSpanScale scale = TimeSpanScale.Days;
             long value = 0;
             while ((fieldNumber = source.ReadFieldHeader()) > 0)
             {
                 switch (fieldNumber)
                 {
                     case FieldTimeSpanScale:
                         scale = (TimeSpanScale)source.ReadInt32();
                         break;
                     case FieldTimeSpanValue:
                         source.Assert(WireType.SignedVariant);
                         value = source.ReadInt64();
                         break;
                     default:
                         source.SkipField();
                         break;
                 }
             }
             ProtoReader.EndSubItem(token, source);
             switch (scale)
             {
                 case TimeSpanScale.Days:
                     return value * TimeSpan.TicksPerDay;
                 case TimeSpanScale.Hours:
                     return value * TimeSpan.TicksPerHour;
                 case TimeSpanScale.Minutes:
                     return value * TimeSpan.TicksPerMinute;
                 case TimeSpanScale.Seconds:
                     return value * TimeSpan.TicksPerSecond;
                 case TimeSpanScale.Milliseconds:
                     return value * TimeSpan.TicksPerMillisecond;
                 case TimeSpanScale.Ticks:
                     return value;
                 case TimeSpanScale.MinMax:
                     switch (value)
                     {
                         case 1: return long.MaxValue;
                         case -1: return long.MinValue;
                         default: throw new ProtoException("Unknown min/max value: " + value.ToString());
                     }
                 default:
                     throw new ProtoException("Unknown timescale: " + scale.ToString());
             }
         case WireType.Fixed64:
             return source.ReadInt64();
         default:
             throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
     }
 }
开发者ID:tsuixl,项目名称:Frame,代码行数:56,代码来源:BclHelpers.cs

示例4: ReadTimeSpanTicks

 private static long ReadTimeSpanTicks(ProtoReader source)
 {
     switch (source.WireType)
     {
     case WireType.Fixed64:
         return source.ReadInt64();
     case WireType.String:
     case WireType.StartGroup:
     {
         SubItemToken token = ProtoReader.StartSubItem(source);
         TimeSpanScale timeSpanScale = TimeSpanScale.Days;
         long num = 0L;
         int num2;
         while ((num2 = source.ReadFieldHeader()) > 0)
         {
             int num3 = num2;
             if (num3 != 1)
             {
                 if (num3 != 2)
                 {
                     source.SkipField();
                 }
                 else
                 {
                     timeSpanScale = (TimeSpanScale)source.ReadInt32();
                 }
             }
             else
             {
                 source.Assert(WireType.SignedVariant);
                 num = source.ReadInt64();
             }
         }
         ProtoReader.EndSubItem(token, source);
         TimeSpanScale timeSpanScale2 = timeSpanScale;
         switch (timeSpanScale2)
         {
         case TimeSpanScale.Days:
             return num * 864000000000L;
         case TimeSpanScale.Hours:
             return num * 36000000000L;
         case TimeSpanScale.Minutes:
             return num * 600000000L;
         case TimeSpanScale.Seconds:
             return num * 10000000L;
         case TimeSpanScale.Milliseconds:
             return num * 10000L;
         case TimeSpanScale.Ticks:
             return num;
         default:
         {
             if (timeSpanScale2 != TimeSpanScale.MinMax)
             {
                 throw new ProtoException("Unknown timescale: " + timeSpanScale.ToString());
             }
             long num4 = num;
             if (num4 >= -1L && num4 <= 1L)
             {
                 switch ((int)(num4 - -1L))
                 {
                 case 0:
                     return -9223372036854775808L;
                 case 2:
                     return 9223372036854775807L;
                 }
             }
             throw new ProtoException("Unknown min/max value: " + num.ToString());
         }
         }
         break;
     }
     default:
         throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
     }
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:75,代码来源:BclHelpers.cs

示例5: ReadNetObject

        /// <summary>
        /// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
        /// </summary>
        public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
        {
            SubItemToken token = ProtoReader.StartSubItem(source);
            int fieldNumber;
            int newObjectKey = -1, newTypeKey = -1, tmp;
            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                    case FieldExistingObjectKey:
                        tmp = source.ReadInt32();
                        value = source.NetCache.GetKeyedObject(tmp);
                        break;
                    case FieldNewObjectKey:
                        newObjectKey = source.ReadInt32();
                        break;
                    case FieldExistingTypeKey:
                        tmp = source.ReadInt32();
                        type = (Type)source.NetCache.GetKeyedObject(tmp);
                        key = source.GetTypeKey(ref type);
                        break;
                    case FieldNewTypeKey:
                        newTypeKey = source.ReadInt32();
                        break;
                    case FieldTypeName:
                        type = source.DeserializeType(source.ReadString());
                        key = source.GetTypeKey(ref type);
                        break;
                    case FieldObject:
                        bool isString = type == typeof(string);
                        bool lateSet = value == null && isString;
                        if (value == null && !lateSet)
                        {
                            value = ((options & NetObjectOptions.UseConstructor) == 0) ? BclHelpers.GetUninitializedObject(type) : Activator.CreateInstance(type);
                        }
                        if (newObjectKey >= 0 && !lateSet)
                        {
                            source.NetCache.SetKeyedObject(newObjectKey, value);
                            if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                        object oldValue = value;
                        if (isString)
                        {
                            value = source.ReadString();
                        }
                        else
                        {
                            value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
                        }

                        if (newObjectKey >= 0 && lateSet)
                        {
                            source.NetCache.SetKeyedObject(newObjectKey, value);
                            if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                        if (!lateSet && !ReferenceEquals(oldValue, value))
                        {
                            throw new ProtoException("A reference-tracked object changed reference during deserialization");
                        }
                        break;
                    default:
                        source.SkipField();
                        break;
                }
            }
            ProtoReader.EndSubItem(token, source);

            return value;
        }
开发者ID:helios57,项目名称:anrl,代码行数:72,代码来源:BclHelpers.cs

示例6: ReadNetObject

 public static object ReadNetObject(object value, ProtoReader source, int key, Type type, BclHelpers.NetObjectOptions options)
 {
     SubItemToken token = ProtoReader.StartSubItem(source);
     int num = -1;
     int num2 = -1;
     int num3;
     while ((num3 = source.ReadFieldHeader()) > 0)
     {
         switch (num3)
         {
         case 1:
         {
             int key2 = source.ReadInt32();
             value = source.NetCache.GetKeyedObject(key2);
             continue;
         }
         case 2:
             num = source.ReadInt32();
             continue;
         case 3:
         {
             int key2 = source.ReadInt32();
             type = (Type)source.NetCache.GetKeyedObject(key2);
             key = source.GetTypeKey(ref type);
             continue;
         }
         case 4:
             num2 = source.ReadInt32();
             continue;
         case 8:
         {
             string text = source.ReadString();
             type = source.DeserializeType(text);
             if (type == null)
             {
                 throw new ProtoException("Unable to resolve type: " + text + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
             }
             if (type == typeof(string))
             {
                 key = -1;
             }
             else
             {
                 key = source.GetTypeKey(ref type);
                 if (key < 0)
                 {
                     throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                 }
             }
             continue;
         }
         case 10:
         {
             bool flag = type == typeof(string);
             bool flag2 = value == null;
             bool flag3 = flag2 && (flag || (byte)(options & BclHelpers.NetObjectOptions.LateSet) != 0);
             if (num >= 0 && !flag3)
             {
                 if (value == null)
                 {
                     source.TrapNextObject(num);
                 }
                 else
                 {
                     source.NetCache.SetKeyedObject(num, value);
                 }
                 if (num2 >= 0)
                 {
                     source.NetCache.SetKeyedObject(num2, type);
                 }
             }
             object obj = value;
             if (flag)
             {
                 value = source.ReadString();
             }
             else
             {
                 value = ProtoReader.ReadTypedObject(obj, key, source, type);
             }
             if (num >= 0)
             {
                 if (flag2 && !flag3)
                 {
                     obj = source.NetCache.GetKeyedObject(num);
                 }
                 if (flag3)
                 {
                     source.NetCache.SetKeyedObject(num, value);
                     if (num2 >= 0)
                     {
                         source.NetCache.SetKeyedObject(num2, type);
                     }
                 }
             }
             if (num >= 0 && !flag3 && !object.ReferenceEquals(obj, value))
             {
                 throw new ProtoException("A reference-tracked object changed reference during deserialization");
             }
             if (num < 0 && num2 >= 0)
//.........这里部分代码省略.........
开发者ID:floatyears,项目名称:Decrypt,代码行数:101,代码来源:BclHelpers.cs

示例7: ReadField

 object ReadField(ProtoReader reader, Type memberT, string sClassName, CLS_Environment environment)
 {
     if (memberT == typeof(int))
     {
         return reader.ReadInt32();
     }
     else if (memberT == typeof(uint))
     {
         return reader.ReadUInt32();
     }
     else if (memberT == typeof(bool))
     {
         return reader.ReadBoolean();
     }
     else if (memberT == typeof(byte))
     {
         return reader.ReadByte();
     }
     else if (memberT == typeof(sbyte))
     {
         return reader.ReadSByte();
     }
     else if (memberT == typeof(float))
     {
         return reader.ReadSingle();
     }
     else if (memberT == typeof(double))
     {
         return reader.ReadDouble();
     }
     else if (memberT == typeof(short))
     {
         return reader.ReadInt16();
     }
     else if (memberT == typeof(ushort))
     {
         return reader.ReadUInt16();
     }
     else if (memberT == typeof(long))
     {
         return reader.ReadInt64();
     }
     else if (memberT == typeof(ulong))
     {
         return reader.ReadUInt64();
     }
     else if (memberT == typeof(string))
     {
         return reader.ReadString();
     }
     else if (memberT == typeof(byte[]))
     {
         return ProtoReader.AppendBytes(null, reader);
     }
     else if (memberT == typeof(SInstance))
     {
         SubItemToken st = ProtoReader.StartSubItem(reader);
         CLS_Type_Class sClass = environment.GetTypeByKeywordQuiet(sClassName) as CLS_Type_Class;
         if (!sClass.compiled)
             RuntimeCompilerClass(sClassName);
         CLS_Content content = CLS_Content.NewContent(environment);
         CLS_Content.Value retVal = sClass.function.New(content, m_emptyParams);
         CLS_Content.PoolContent(content);
         SInstance sInstance = (SInstance)retVal.value;
         ReadSInstance(reader, sInstance, environment);
         ProtoReader.EndSubItem(st, reader);
         return sInstance;
     }
     else
     {
         throw new NotImplementedException("未实现类型: " + memberT);
     }
 }
开发者ID:wpszz,项目名称:CSLightForUnity,代码行数:73,代码来源:CSLightMng_ProtoBuf.cs

示例8: Read

        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="targetPlatform">
        /// The target platform.
        /// </param>
        /// <param name="protoReader">
        /// The proto reader.
        /// </param>
        /// <returns>
        /// The <see cref="TargetPlatform"/>.
        /// </returns>
        private static TargetPlatform Read(TargetPlatform targetPlatform, ProtoReader protoReader)
        {
            int num = protoReader.ReadInt32();
            var result = TargetPlatform.Windows;
            if (num != 0)
            {
                if (num != 1)
                {
                    if (num != 2)
                    {
                        if (num != 3)
                        {
                            if (num != 4)
                            {
                                if (num != 5)
                                {
                                    if (num != 6)
                                    {
                                        if (num != 7)
                                        {
                                            if (num != 8)
                                            {
                                                if (num != 9)
                                                {
                                                    if (num != 10)
                                                    {
                                                        if (num != 11)
                                                        {
                                                            if (num != 12)
                                                            {
                                                                protoReader.ThrowEnumException(
                                                                    typeof(TargetPlatform), 
                                                                    num);
                                                            }
                                                            else
                                                            {
                                                                result = TargetPlatform.RaspberryPi;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            result = TargetPlatform.WindowsPhone8;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        result = TargetPlatform.PlayStationMobile;
                                                    }
                                                }
                                                else
                                                {
                                                    result = TargetPlatform.Ouya;
                                                }
                                            }
                                            else
                                            {
                                                result = TargetPlatform.NativeClient;
                                            }
                                        }
                                        else
                                        {
                                            result = TargetPlatform.WindowsStoreApp;
                                        }
                                    }
                                    else
                                    {
                                        result = TargetPlatform.MacOSX;
                                    }
                                }
                                else
                                {
                                    result = TargetPlatform.Linux;
                                }
                            }
                            else
                            {
                                result = TargetPlatform.Android;
                            }
                        }
                        else
                        {
                            result = TargetPlatform.iOS;
                        }
                    }
                    else
                    {
                        result = TargetPlatform.WindowsPhone;
                    }
//.........这里部分代码省略.........
开发者ID:RedpointGames,项目名称:Protogame,代码行数:101,代码来源:CompiledAssetSerializer.cs

示例9: Read

 private static Product Read(Product product1, ProtoReader reader1)
 {
     int num;
     while ((num = reader1.ReadFieldHeader()) > 0)
     {
         switch (num)
         {
             case 1:
                 if (product1 == null)
                 {
                     product1 = new Product();
                 }
                 product1.ProductID = reader1.ReadInt32();
                 continue;
             case 2:
                 if (product1 == null)
                 {
                     product1 = new Product();
                 }
                 product1.ProductName = reader1.ReadString();
                 continue;
             case 3:
                 if (product1 == null)
                 {
                     product1 = new Product();
                 }
                 product1.SupplierID = new int?(reader1.ReadInt32());
                 continue;
         }
     }
     return product1;
 }
开发者ID:XewTurquish,项目名称:vsminecraft,代码行数:32,代码来源:Program.cs


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