Exemplo n.º 1
0
        public static decimal DeserializeDecimal(SerializationContext context)
        {
            ulong low = 0;
            uint high = 0;
            uint signScale = 0;

            uint prefix;
            bool keepRunning = true;
            while (keepRunning && context.TryReadFieldPrefix(out prefix))
            {
                switch (prefix)
                {
                    case (FieldDecimalLow << 3) | (int)WireType.Variant:
                        low = (ulong)context.DecodeInt64();
                        break;
                    case (FieldDecimalHigh << 3) | (int)WireType.Variant:
                        high = (uint)context.DecodeInt32();
                        break;
                    case (FieldDecimalSignScale << 3) | (int)WireType.Variant:
                        signScale = (uint)context.DecodeInt32();
                        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 FieldDecimalHigh:
                            case FieldDecimalLow:
                            case FieldDecimalSignScale:
                                throw new ProtoException("Incorrect wire-type deserializing Decimal");
                            default:
                                Serializer.SkipData(context, fieldTag, wireType);
                                break;
                        }
                        break;
                }
            }

            if (low == 0 && high == 0) return decimal.Zero;

            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);
        }
Exemplo n.º 2
0
 public override long DeserializeImpl(TSource source, SerializationContext context)
 {
     return(context.DecodeInt64());
 }
Exemplo n.º 3
0
        public static decimal DeserializeDecimal(SerializationContext context)
        {
            ulong low       = 0;
            uint  high      = 0;
            uint  signScale = 0;

            uint prefix;
            bool keepRunning = true;

            while (keepRunning && context.TryReadFieldPrefix(out prefix))
            {
                switch (prefix)
                {
                case (FieldDecimalLow << 3) | (int)WireType.Variant:
                    low = (ulong)context.DecodeInt64();
                    break;

                case (FieldDecimalHigh << 3) | (int)WireType.Variant:
                    high = (uint)context.DecodeInt32();
                    break;

                case (FieldDecimalSignScale << 3) | (int)WireType.Variant:
                    signScale = (uint)context.DecodeInt32();
                    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 FieldDecimalHigh:
                    case FieldDecimalLow:
                    case FieldDecimalSignScale:
                        throw new ProtoException("Incorrect wire-type deserializing Decimal");

                    default:
                        Serializer.SkipData(context, fieldTag, wireType);
                        break;
                    }
                    break;
                }
            }

            if (low == 0 && high == 0)
            {
                return(decimal.Zero);
            }

            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));
        }