Пример #1
0
        public static decimal ReadDecimal(ProtoReader reader)
        {
            int          num4;
            ulong        num   = 0L;
            uint         num2  = 0;
            uint         num3  = 0;
            SubItemToken token = ProtoReader.StartSubItem(reader);

            while ((num4 = reader.ReadFieldHeader()) > 0)
            {
                switch (num4)
                {
                case 1:
                {
                    num = reader.ReadUInt64();
                    continue;
                }

                case 2:
                {
                    num2 = reader.ReadUInt32();
                    continue;
                }

                case 3:
                {
                    num3 = reader.ReadUInt32();
                    continue;
                }
                }
                reader.SkipField();
            }
            ProtoReader.EndSubItem(token, reader);
            if ((num == 0L) && (num2 == 0))
            {
                return(0M);
            }
            int  lo         = (int)(num & 0xffffffffL);
            int  mid        = (int)((num >> 0x20) & 0xffffffffL);
            int  hi         = (int)num2;
            bool isNegative = (num3 & 1) == 1;

            return(new decimal(lo, mid, hi, isNegative, (byte)((num3 & 510) >> 1)));
        }
Пример #2
0
        public static Guid ReadGuid(ProtoReader source)
        {
            int          num3;
            ulong        num   = 0L;
            ulong        num2  = 0L;
            SubItemToken token = ProtoReader.StartSubItem(source);

            while ((num3 = source.ReadFieldHeader()) > 0)
            {
                switch (num3)
                {
                case 1:
                {
                    num = source.ReadUInt64();
                    continue;
                }

                case 2:
                {
                    num2 = source.ReadUInt64();
                    continue;
                }
                }
                source.SkipField();
            }
            ProtoReader.EndSubItem(token, source);
            if ((num == 0L) && (num2 == 0L))
            {
                return(Guid.Empty);
            }
            uint num4 = (uint)(num >> 0x20);
            uint num5 = (uint)num;
            uint num6 = (uint)(num2 >> 0x20);
            uint num7 = (uint)num2;

            return(new Guid((int)num5, (short)num4, (short)(num4 >> 0x10), (byte)num7, (byte)(num7 >> 8), (byte)(num7 >> 0x10), (byte)(num7 >> 0x18), (byte)num6, (byte)(num6 >> 8), (byte)(num6 >> 0x10), (byte)(num6 >> 0x18)));
        }
Пример #3
0
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            long num2;

            switch (source.WireType)
            {
            case WireType.Fixed64:
                return(source.ReadInt64());

            case WireType.String:
            case WireType.StartGroup:
            {
                int           num;
                SubItemToken  token = ProtoReader.StartSubItem(source);
                TimeSpanScale days  = TimeSpanScale.Days;
                num2 = 0L;
Label_0065:
                if ((num = source.ReadFieldHeader()) <= 0)
                {
                    ProtoReader.EndSubItem(token, source);
                    switch (days)
                    {
                    case TimeSpanScale.Days:
                        return(num2 * 0xc92a69c000L);

                    case TimeSpanScale.Hours:
                        return(num2 * 0x861c46800L);

                    case TimeSpanScale.Minutes:
                        return(num2 * 0x23c34600L);

                    case TimeSpanScale.Seconds:
                        return(num2 * 0x989680L);

                    case TimeSpanScale.Milliseconds:
                        return(num2 * 0x2710L);

                    case TimeSpanScale.Ticks:
                        return(num2);

                    case TimeSpanScale.MinMax:
                    {
                        long num4 = num2;
                        if ((num4 <= 1L) && (num4 >= -1L))
                        {
                            switch (((int)(num4 - -1L)))
                            {
                            case 0:
                                return(-9223372036854775808L);

                            case 2:
                                return(0x7fffffffffffffffL);
                            }
                        }
                        goto Label_0115;
                    }
                    }
                    throw new ProtoException("Unknown timescale: " + days.ToString());
                }
                switch (num)
                {
                case 1:
                    source.Assert(WireType.SignedVariant);
                    num2 = source.ReadInt64();
                    goto Label_0065;

                case 2:
                    days = (TimeSpanScale)source.ReadInt32();
                    goto Label_0065;
                }
                source.SkipField();
                goto Label_0065;
            }

            default:
                throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
            }
Label_0115:
            throw new ProtoException("Unknown min/max value: " + num2.ToString());
        }
Пример #4
0
        public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
        {
            int          num;
            SubItemToken token        = ProtoReader.StartSubItem(source);
            int          newObjectKey = -1;
            int          num3         = -1;

            while ((num = source.ReadFieldHeader()) > 0)
            {
                int    num4;
                bool   flag;
                bool   flag2;
                bool   flag3;
                object keyedObject;
                switch (num)
                {
                case 1:
                {
                    num4  = source.ReadInt32();
                    value = source.NetCache.GetKeyedObject(num4);
                    continue;
                }

                case 2:
                {
                    newObjectKey = source.ReadInt32();
                    continue;
                }

                case 3:
                {
                    num4 = source.ReadInt32();
                    type = (Type)source.NetCache.GetKeyedObject(num4);
                    key  = source.GetTypeKey(ref type);
                    continue;
                }

                case 4:
                {
                    num3 = source.ReadInt32();
                    continue;
                }

                case 8:
                {
                    string str = source.ReadString();
                    type = source.DeserializeType(str);
                    if (type == null)
                    {
                        throw new ProtoException("Unable to resolve type: " + str + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
                    }
                    break;
                }

                case 10:
                    flag  = type == typeof(string);
                    flag2 = value == null;
                    flag3 = flag2 && (flag || (((byte)(options & NetObjectOptions.LateSet)) != 0));
                    if ((newObjectKey < 0) || flag3)
                    {
                        goto Label_0180;
                    }
                    if (value != null)
                    {
                        goto Label_0162;
                    }
                    source.TrapNextObject(newObjectKey);
                    goto Label_016F;

                default:
                    goto Label_020D;
                }
                if (type == typeof(string))
                {
                    key = -1;
                    continue;
                }
                key = source.GetTypeKey(ref type);
                if (key >= 0)
                {
                    continue;
                }
                throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
Label_0162:
                source.NetCache.SetKeyedObject(newObjectKey, value);
Label_016F:
                if (num3 >= 0)
                {
                    source.NetCache.SetKeyedObject(num3, type);
                }
Label_0180:
                keyedObject = value;
                if (flag)
                {
                    value = source.ReadString();
                }
                else
                {
                    value = ProtoReader.ReadTypedObject(keyedObject, key, source, type);
                }
                if (newObjectKey >= 0)
                {
                    if (flag2 && !flag3)
                    {
                        keyedObject = source.NetCache.GetKeyedObject(newObjectKey);
                    }
                    if (flag3)
                    {
                        source.NetCache.SetKeyedObject(newObjectKey, value);
                        if (num3 >= 0)
                        {
                            source.NetCache.SetKeyedObject(num3, type);
                        }
                    }
                }
                if (((newObjectKey >= 0) && !flag3) && !object.ReferenceEquals(keyedObject, value))
                {
                    throw new ProtoException("A reference-tracked object changed reference during deserialization");
                }
                if ((newObjectKey < 0) && (num3 >= 0))
                {
                    source.NetCache.SetKeyedObject(num3, type);
                }
                continue;
Label_020D:
                source.SkipField();
            }
            if ((newObjectKey >= 0) && (((byte)(options & NetObjectOptions.AsReference)) == 0))
            {
                throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
            }
            ProtoReader.EndSubItem(token, source);
            return(value);
        }