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


C# SerializationContext.TryReadFieldPrefix方法代码示例

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


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

示例1: DeserializeDecimal

        public static decimal DeserializeDecimal(SerializationContext context)
        {
            ulong low = 0;
            uint high = 0;
            uint signScale = 0;

            uint prefix;
            bool keepRunning = true;
            while (keepRunning && context.TryReadFieldPrefix(out prefix))
            {
                switch (prefix)
                {
                    case (FieldDecimalLow << 3) | (int)WireType.Variant:
                        low = (ulong)context.DecodeInt64();
                        break;
                    case (FieldDecimalHigh << 3) | (int)WireType.Variant:
                        high = (uint)context.DecodeInt32();
                        break;
                    case (FieldDecimalSignScale << 3) | (int)WireType.Variant:
                        signScale = (uint)context.DecodeInt32();
                        break;
                    default:
                        WireType wireType;
                        int fieldTag;
                        Serializer.ParseFieldToken(prefix, out wireType, out fieldTag);
                        if (wireType == WireType.EndGroup)
                        {
                            context.EndGroup(fieldTag);
                            keepRunning = false;
                            continue;
                        }
                        switch (fieldTag)
                        {
                            case FieldDecimalHigh:
                            case FieldDecimalLow:
                            case FieldDecimalSignScale:
                                throw new ProtoException("Incorrect wire-type deserializing Decimal");
                            default:
                                Serializer.SkipData(context, fieldTag, wireType);
                                break;
                        }
                        break;
                }
            }

            if (low == 0 && high == 0) return decimal.Zero;

            int lo = (int)(low & 0xFFFFFFFFL),
                mid = (int)((low >> 32) & 0xFFFFFFFFL),
                hi = (int)high;
            bool isNeg = (signScale & 0x0001) == 0x0001;
            byte scale = (byte)((signScale & 0x01FE) >> 1);
            return new decimal(lo, mid, hi, isNeg, scale);
        }
开发者ID:amwtke,项目名称:commonlibrary,代码行数:54,代码来源:ProtoDecimal.cs

示例2: Deserialize

        internal static Guid Deserialize(SerializationContext context)
        {
            byte[] buffer = new byte[16];

            uint prefix;
            bool keepRunning = true;
            while (keepRunning && context.TryReadFieldPrefix(out prefix))
            {
                switch (prefix)
                {
                    case (FieldLo << 3) | (int)WireType.Fixed64:
                        context.ReadBlock(buffer, 0, 8);
                        break;
                    case (FieldHi << 3) | (int)WireType.Fixed64:
                        context.ReadBlock(buffer, 8, 8);
                        break;
                    default:
                        WireType wireType;
                        int fieldTag;
                        Serializer.ParseFieldToken(prefix, out wireType, out fieldTag);
                        if (wireType == WireType.EndGroup)
                        {
                            context.EndGroup(fieldTag);
                            keepRunning = false;
                            continue;
                        }
                        switch (fieldTag)
                        {
                            case FieldLo:
                            case FieldHi:
                                throw new ProtoException("Incorrect wire-type deserializing Guid");
                            default:
                                Serializer.SkipData(context, fieldTag, wireType);
                                break;
                        }
                        break;
                }
            }
            return new Guid(buffer);
        }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:40,代码来源:ProtoGuid.cs

示例3: DeserializeTicks

        private static long DeserializeTicks(SerializationContext context)
        {
            long value = 0;
            TimeSpanScale scale = TimeSpanScale.Days;

            uint prefix;
            bool keepRunning = true;
            while (keepRunning && context.TryReadFieldPrefix(out prefix))
            {
                switch (prefix)
                {
                    case (FieldTimeSpanScale << 3) | (int)WireType.Variant:
                        scale = (TimeSpanScale)context.DecodeInt32();
                        break;
                    case (FieldTimeSpanValue << 3) | (int)WireType.Variant:
                        value = SerializationContext.Zag(context.DecodeUInt64());
                        break;
                    default:
                        WireType wireType;
                        int fieldTag;
                        Serializer.ParseFieldToken(prefix, out wireType, out fieldTag);
                        if (wireType == WireType.EndGroup)
                        {
                            context.EndGroup(fieldTag);
                            keepRunning = false;
                            continue;
                        }
                        switch (fieldTag)
                        {
                            case FieldTimeSpanScale:
                            case FieldTimeSpanValue:
                                throw new ProtoException("Incorrect wire-type deserializing TimeSpan");
                            default:
                                Serializer.SkipData(context, fieldTag, wireType);
                                break;
                        }
                        break;
                }
            }

            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());
            }
        }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:65,代码来源:ProtoTimeSpan.cs


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