Esempio n. 1
0
        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());
            }
        }
Esempio n. 2
0
        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());
            }
        }
Esempio n. 3
0
 public override ulong DeserializeImpl(TSource source, SerializationContext context)
 {
     return(context.DecodeUInt64());
 }