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


C# ProtoBuf.ProtoReader类代码示例

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


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

示例1: ReaderContext

 public ReaderContext(Stream stream)
 {
     this.Reader = new ProtoReader(stream, TypeModel.Create(), null);
     this.ReadingAction = ReadingActionType.ReadHeader;
     this.Root = new VisitingNode(NoParent);
     this.ParentVisitingNode = this.Root;
 }
开发者ID:r3c,项目名称:verse,代码行数:7,代码来源:ReaderContext.cs

示例2: Deserialize

 /// <summary>
 /// The deserialize.
 /// </summary>
 /// <param name="num">
 /// The num.
 /// </param>
 /// <param name="obj">
 /// The obj.
 /// </param>
 /// <param name="protoReader">
 /// The proto reader.
 /// </param>
 /// <returns>
 /// The <see cref="object"/>.
 /// </returns>
 protected override object Deserialize(int num, object obj, ProtoReader protoReader)
 {
     switch (num)
     {
         case 0:
             return Read((MxMessage)obj, protoReader);
         case 1:
             return Read((MxPayload)obj, protoReader);
         default:
             return null;
     }
 }
开发者ID:johnsonc,项目名称:Protogame,代码行数:27,代码来源:MxMessageSerializer.cs

示例3: ReadDateTime

 public static DateTime ReadDateTime(ProtoReader source)
 {
     long num = BclHelpers.ReadTimeSpanTicks(source);
     if (num == -9223372036854775808L)
     {
         return DateTime.MinValue;
     }
     if (num == 9223372036854775807L)
     {
         return DateTime.MaxValue;
     }
     return BclHelpers.EpochOrigin.AddTicks(num);
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:13,代码来源:BclHelpers.cs

示例4: Deserialize

 /// <summary>
 /// The deserialize.
 /// </summary>
 /// <param name="num">
 /// The num.
 /// </param>
 /// <param name="obj">
 /// The obj.
 /// </param>
 /// <param name="protoReader">
 /// The proto reader.
 /// </param>
 /// <returns>
 /// The <see cref="object"/>.
 /// </returns>
 protected override object Deserialize(int num, object obj, ProtoReader protoReader)
 {
     switch (num)
     {
         case 0:
             return Read((CompiledAsset)obj, protoReader);
         case 1:
             return Read((PlatformData)obj, protoReader);
         case 2:
             return _2(obj, protoReader);
         default:
             return null;
     }
 }
开发者ID:RedpointGames,项目名称:Protogame,代码行数:29,代码来源:CompiledAssetSerializer.cs

示例5: TestRandomDataWithReader

        public void TestRandomDataWithReader()
        {
            var input = File.ReadAllBytes("protobuf-net.dll");
            var stream = new MemoryStream(input);
            stream.Seek(0, SeekOrigin.Begin);
            Assert.Greater(3, 0); // I always double-check the param order
            Assert.Greater(stream.Length, 0);

            using (var reader = new ProtoReader(stream, null, null))
            {
                while (reader.ReadFieldHeader() > 0)
                {
                    reader.SkipField();
                }
            }
        }
开发者ID:XewTurquish,项目名称:vsminecraft,代码行数:16,代码来源:SO9398578.cs

示例6: ReadDecimal

 public static decimal ReadDecimal(ProtoReader reader)
 {
     ulong num = 0uL;
     uint num2 = 0u;
     uint num3 = 0u;
     SubItemToken token = ProtoReader.StartSubItem(reader);
     int num4;
     while ((num4 = reader.ReadFieldHeader()) > 0)
     {
         switch (num4)
         {
         case 1:
             num = reader.ReadUInt64();
             break;
         case 2:
             num2 = reader.ReadUInt32();
             break;
         case 3:
             num3 = reader.ReadUInt32();
             break;
         default:
             reader.SkipField();
             break;
         }
     }
     ProtoReader.EndSubItem(token, reader);
     if (num == 0uL && num2 == 0u)
     {
         return 0m;
     }
     int lo = (int)(num & 0xFFFFFFFFL);
     int mid = (int)(num >> 32 & 0xFFFFFFFFL);
     int hi = (int)num2;
     bool isNegative = (num3 & 1u) == 1u;
     byte scale = (byte)((num3 & 510u) >> 1);
     return new decimal(lo, mid, hi, isNegative, scale);
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:37,代码来源:BclHelpers.cs

示例7: StartSubItem

 /// <summary>
 /// Begins consuming a nested message in the stream; supported wire-types: StartGroup, String
 /// </summary>
 /// <remarks>The token returned must be help and used when callining EndSubItem</remarks>
 public static SubItemToken StartSubItem(ProtoReader reader)
 {
     switch (reader.wireType)
     {
         case WireType.StartGroup:
             reader.wireType = WireType.None; // to prevent glitches from double-calling
             reader.depth++;
             return new SubItemToken(-reader.fieldNumber);
         case WireType.String:
             int len = (int)reader.ReadUInt32Variant(false);
             if (len < 0) throw AddErrorData(new InvalidOperationException(), reader);
             int lastEnd = reader.blockEnd;
             reader.blockEnd = reader.position + len;
             reader.depth++;
             return new SubItemToken(lastEnd);
         default:
             throw reader.CreateException(); // throws
     }
 }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:23,代码来源:ProtoReader.cs

示例8: EndSubItem

 /// <summary>
 /// Makes the end of consuming a nested message in the stream; the stream must be either at the correct EndGroup
 /// marker, or all fields of the sub-message must have been consumed (in either case, this means ReadFieldHeader
 /// should return zero)
 /// </summary>
 public static void EndSubItem(SubItemToken token, ProtoReader reader)
 {
     int value = token.value;
     switch (reader.wireType)
     {
         case WireType.EndGroup:
             if (value >= 0) throw AddErrorData(new ArgumentException("token"), reader);
             if (-value != reader.fieldNumber) throw reader.CreateException(); // wrong group ended!
             reader.wireType = WireType.None; // this releases ReadFieldHeader
             reader.depth--;
             break;
         // case WireType.None: // TODO reinstate once reads reset the wire-type
         default:
             if (value < reader.position) throw reader.CreateException();
             if (reader.blockEnd != reader.position && reader.blockEnd != int.MaxValue) throw reader.CreateException();
             reader.blockEnd = value;
             reader.depth--;
             break;
         /*default:
             throw reader.BorkedIt(); */
     }
 }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:27,代码来源:ProtoReader.cs

示例9: ReadObject

 /// <summary>
 /// Reads (merges) a sub-message from the stream, internally calling StartSubItem and EndSubItem, and (in between)
 /// parsing the message in accordance with the model associated with the reader
 /// </summary>
 public static object ReadObject(object value, int key, ProtoReader reader)
 {
     if (reader.model == null)
     {
         throw AddErrorData(new InvalidOperationException("Cannot deserialize sub-objects unless a model is provided"), reader);
     }
     SubItemToken token = ProtoReader.StartSubItem(reader);
     value = reader.model.Deserialize(key, value, reader);
     ProtoReader.EndSubItem(token, reader);
     return value;
 }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:15,代码来源:ProtoReader.cs

示例10: HasSubValue

 /// <summary>
 /// Indicates whether the reader still has data remaining in the current sub-item,
 /// additionally setting the wire-type for the next field if there is more data.
 /// This is used when decoding packed data.
 /// </summary>
 public static bool HasSubValue(ProtoBuf.WireType wireType, ProtoReader source)
 {
     // check for virtual end of stream
     if (source.blockEnd <= source.position || wireType == WireType.EndGroup) { return false; } 
     source.wireType = wireType;
     return true;
 }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:12,代码来源:ProtoReader.cs

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

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

示例13: EoF

 private static Exception EoF(ProtoReader source) {
     return AddErrorData(new EndOfStreamException(), source);
 }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:3,代码来源:ProtoReader.cs

示例14: ReadTimeSpan

 /// <summary>
 /// Parses a TimeSpan from a protobuf stream
 /// </summary>        
 public static TimeSpan ReadTimeSpan(ProtoReader source)
 {
     long ticks = ReadTimeSpanTicks(source);
     if (ticks == long.MinValue) return TimeSpan.MinValue;
     if (ticks == long.MaxValue) return TimeSpan.MaxValue;
     return TimeSpan.FromTicks(ticks);
 }
开发者ID:tsuixl,项目名称:Frame,代码行数:10,代码来源:BclHelpers.cs

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


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