Ejemplo n.º 1
0
        ScaledTicks ISerializer <ScaledTicks> .Read(ref ProtoReader.State state, ScaledTicks _)
        {
            int           fieldNumber;
            TimeSpanScale scale = TimeSpanScale.Days;
            long          value = 0;
            var           kind  = DateTimeKind.Unspecified;

            while ((fieldNumber = state.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                case ScaledTicks.FieldTimeSpanScale:
                    scale = (TimeSpanScale)state.ReadInt32();
                    break;

                case ScaledTicks.FieldTimeSpanValue:
                    state.Assert(WireType.SignedVarint);
                    value = state.ReadInt64();
                    break;

                case ScaledTicks.FieldTimeSpanKind:
                    kind = (DateTimeKind)state.ReadInt32();
                    switch (kind)
                    {
                    case DateTimeKind.Unspecified:
                    case DateTimeKind.Utc:
                    case DateTimeKind.Local:
                        break;         // fine

                    default:
                        ThrowHelper.ThrowProtoException("Invalid date/time kind: " + kind.ToString());
                        break;
                    }
                    break;

                default:
                    state.SkipField();
                    break;
                }
            }
            return(new ScaledTicks(value, scale, kind));
        }