Пример #1
0
        private static Duration ReadDurationFallback(ref ProtoReader.State state, Duration value)
        {
            var seconds = value.Seconds;
            var nanos   = value.Nanoseconds;
            int fieldNumber;

            while ((fieldNumber = state.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                case 1:
                    seconds = state.ReadInt64();
                    break;

                case 2:
                    nanos = state.ReadInt32();
                    break;

                default:
                    state.SkipField();
                    break;
                }
            }
            return(new Duration(seconds, nanos));
        }
Пример #2
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));
        }
Пример #3
0
 public CustomType Read(ref ProtoReader.State state, CustomType value)
 => state.ReadInt64();
Пример #4
0
 public object Read(ref ProtoReader.State state, object value)
 {
     Debug.Assert(value == null); // since replaces
     return(state.ReadInt64());
 }