Beispiel #1
0
        LocalTime ISerializer <LocalTime> .Read(ref ProtoReader.State state, LocalTime value)
        {
            int field;
            int hours = value.Hour, minutes = value.Minute, seconds = value.Second, nanos = value.NanosecondOfSecond;

            while ((field = state.ReadFieldHeader()) > 0)
            {
                switch (field)
                {
                case 1:
                    hours = state.ReadInt32();
                    break;

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

                case 3:
                    seconds = state.ReadInt32();
                    break;

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

                default:
                    state.SkipField();
                    break;
                }
            }
            return(new LocalTime(hours, minutes, seconds).PlusNanoseconds(nanos));
        }
Beispiel #2
0
        public KeyValuePair <TKey, TValue> Read(ref ProtoReader.State state, KeyValuePair <TKey, TValue> pair)
        {
            TKey   key   = pair.Key;
            TValue value = pair.Value;
            int    field;

            while ((field = state.ReadFieldHeader()) > 0)
            {
                switch (field)
                {
                case 1:
                    key = state.ReadAny(_keyFeatures, key, _keySerializer);
                    break;

                case 2:
                    value = state.ReadAny(_valueFeatures, value, _valueSerializer);
                    break;

                default:
                    state.SkipField();
                    break;
                }
            }
            if (TypeHelper <TKey> .IsReferenceType && TypeHelper <TKey> .ValueChecker.IsNull(key))
            {
                key = TypeModel.CreateInstance <TKey>(state.Context, _keySerializer);
            }
            if (TypeHelper <TValue> .IsReferenceType && TypeHelper <TValue> .ValueChecker.IsNull(value))
            {
                value = TypeModel.CreateInstance <TValue>(state.Context, _valueSerializer);
            }

            return(new KeyValuePair <TKey, TValue>(key, value));
        }
Beispiel #3
0
        LocalDate ISerializer <LocalDate> .Read(ref ProtoReader.State state, LocalDate value)
        {
            int field;
            int year = value.Year, month = value.Month, day = value.Day;

            while ((field = state.ReadFieldHeader()) > 0)
            {
                switch (field)
                {
                case 1:
                    year = state.ReadInt32();
                    break;

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

                case 3:
                    day = state.ReadInt32();
                    break;

                default:
                    state.SkipField();
                    break;
                }
            }
            return(new LocalDate(year, month, day)); // ISO calendar is implicit
        }
Beispiel #4
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));
        }
Beispiel #5
0
        public object Read(ref ProtoReader.State state, object value)
        {
            object[] values     = new object[members.Length];
            bool     invokeCtor = false;

            if (value == null)
            {
                invokeCtor = true;
            }
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = GetValue(value, i);
            }
            int field;

            while ((field = state.ReadFieldHeader()) > 0)
            {
                invokeCtor = true;
                if (field <= tails.Length)
                {
                    IRuntimeProtoSerializerNode tail = tails[field - 1];
                    values[field - 1] = tails[field - 1].Read(ref state, tail.RequiresOldValue ? values[field - 1] : null);
                }
                else
                {
                    state.SkipField();
                }
            }
            return(invokeCtor ? ctor.Invoke(values) : value);
        }
Beispiel #6
0
        decimal ISerializer <decimal> .Read(ref ProtoReader.State state, decimal value)
        {
            ulong low       = 0;
            uint  high      = 0;
            uint  signScale = 0;
            int   fieldNumber;

            while ((fieldNumber = state.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                case FieldDecimalLow: low = state.ReadUInt64(); break;

                case FieldDecimalHigh: high = state.ReadUInt32(); break;

                case FieldDecimalSignScale: signScale = state.ReadUInt32(); break;

                default: state.SkipField(); break;
                }
            }
            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));
        }
                public MyMessage Read(ref ProtoReader.State state, MyMessage value)
                {
                    value ??= new MyMessage();
                    int field;

                    while ((field = state.ReadFieldHeader()) > 0)
                    {
                        switch (field)
                        {
                        case 12: value.Y = state.ReadString(); break;

                        case 42: value.X = state.ReadInt32(); break;

                        default: state.SkipField(); break;
                        }
                    }
                    return(value);
                }
Beispiel #8
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));
        }