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


C# ProtoReader.Assert方法代码示例

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


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

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

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


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