Ejemplo n.º 1
0
        public static float ReadValue <TInput>(ref Reader <TInput> reader, Field field)
        {
            ReferenceCodec.MarkValueField(reader.Session);
            switch (field.WireType)
            {
            case WireType.Fixed32:
                return(ReadFloatRaw(ref reader));

            case WireType.Fixed64:
            {
                var value = DoubleCodec.ReadDoubleRaw(ref reader);
                if ((value > float.MaxValue || value < float.MinValue) && !double.IsInfinity(value) && !double.IsNaN(value))
                {
                    ThrowValueOutOfRange(value);
                }

                return((float)value);
            }

            case WireType.LengthPrefixed:
                return((float)DecimalCodec.ReadDecimalRaw(ref reader));

            default:
                ThrowWireTypeOutOfRange(field.WireType);
                return(0);
            }
        }
Ejemplo n.º 2
0
        public static decimal ReadValue <TInput>(ref Reader <TInput> reader, Field field)
        {
            ReferenceCodec.MarkValueField(reader.Session);
            switch (field.WireType)
            {
            case WireType.Fixed32:
            {
                var value = FloatCodec.ReadFloatRaw(ref reader);
                if (value > (float)decimal.MaxValue || value < (float)decimal.MinValue)
                {
                    ThrowValueOutOfRange(value);
                }

                return((decimal)value);
            }

            case WireType.Fixed64:
            {
                var value = DoubleCodec.ReadDoubleRaw(ref reader);
                if (value > (double)decimal.MaxValue || value < (double)decimal.MinValue)
                {
                    ThrowValueOutOfRange(value);
                }

                return((decimal)value);
            }

            case WireType.LengthPrefixed:
                return(ReadDecimalRaw(ref reader));

            default:
                ThrowWireTypeOutOfRange(field.WireType);
                return(0);
            }
        }