コード例 #1
0
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            SubItemToken  token = ProtoReader.StartSubItem(source);
            int           fieldNumber;
            TimeSpanScale scale = TimeSpanScale.Days;
            long          value = 0;

            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                case FieldTimeSpanScale:
                    scale = (TimeSpanScale)source.ReadInt32();
                    break;

                case FieldTimeSpanValue:
                    source.Assert(WireType.SignedVariant);
                    value = source.ReadInt64();
                    break;

                default:
                    source.SkipField();
                    break;
                }
            }
            ProtoReader.EndSubItem(token, source);
            switch (scale)
            {
            case TimeSpanScale.Days:
                return(value * TimeSpan.TicksPerDay);

            case TimeSpanScale.Hours:
                return(value * TimeSpan.TicksPerHour);

            case TimeSpanScale.Minutes:
                return(value * TimeSpan.TicksPerMinute);

            case TimeSpanScale.Seconds:
                return(value * TimeSpan.TicksPerSecond);

            case TimeSpanScale.Milliseconds:
                return(value * TimeSpan.TicksPerMillisecond);

            case TimeSpanScale.Ticks:
                return(value);

            case TimeSpanScale.MinMax:
                switch (value)
                {
                case 1: return(long.MaxValue);

                case -1: return(long.MinValue);

                default: throw new ProtoException("Unknown min/max value: " + value.ToString());
                }

            default:
                throw new ProtoException("Unknown timescale: " + scale.ToString());
            }
        }
コード例 #2
0
        /// <summary>
        /// Parses a TimeSpan from a protobuf stream using the standardized format, google.protobuf.Duration
        /// </summary>
        public static TimeSpan ReadDuration(ProtoReader source)
        {
            long         seconds = 0;
            int          nanos   = 0;
            SubItemToken token   = ProtoReader.StartSubItem(source);
            int          fieldNumber;

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

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

                default:
                    source.SkipField();
                    break;
                }
            }
            ProtoReader.EndSubItem(token, source);
            return(FromDurationSeconds(seconds, nanos));
        }
コード例 #3
0
        /// <summary>
        /// Parses a Guid from a protobuf stream
        /// </summary>
        public static Guid ReadGuid(ProtoReader source)
        {
            ulong        low = 0, high = 0;
            int          fieldNumber;
            SubItemToken token = ProtoReader.StartSubItem(source);

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

                case FieldGuidHigh: high = source.ReadUInt64(); break;

                default: source.SkipField(); break;
                }
            }
            ProtoReader.EndSubItem(token, source);
            if (low == 0 && high == 0)
            {
                return(Guid.Empty);
            }
            uint a = (uint)(low >> 32), b = (uint)low, c = (uint)(high >> 32), d = (uint)high;

            return(new Guid((int)b, (short)a, (short)(a >> 16),
                            (byte)d, (byte)(d >> 8), (byte)(d >> 16), (byte)(d >> 24),
                            (byte)c, (byte)(c >> 8), (byte)(c >> 16), (byte)(c >> 24)));
        }
コード例 #4
0
        /// <summary>
        /// Parses a decimal from a protobuf stream
        /// </summary>
        public static decimal ReadDecimal(ProtoReader reader)
        {
            ulong low       = 0;
            uint  high      = 0;
            uint  signScale = 0;

            int          fieldNumber;
            SubItemToken token = ProtoReader.StartSubItem(reader);

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

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

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

                default: reader.SkipField(); break;
                }
            }
            ProtoReader.EndSubItem(token, reader);

            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));
        }
コード例 #5
0
        public static decimal ReadDecimal(ProtoReader reader)
        {
            ulong        num          = (ulong)0;
            uint         num1         = 0;
            uint         num2         = 0;
            SubItemToken subItemToken = ProtoReader.StartSubItem(reader);

            while (true)
            {
                int num3 = reader.ReadFieldHeader();
                int num4 = num3;
                if (num3 <= 0)
                {
                    break;
                }
                switch (num4)
                {
                case 1:
                {
                    num = reader.ReadUInt64();
                    continue;
                }

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

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

                default:
                {
                    reader.SkipField();
                    continue;
                }
                }
            }
            ProtoReader.EndSubItem(subItemToken, reader);
            if (num == (long)0 && num1 == 0)
            {
                return(new decimal(0));
            }
            int  num5 = (int)(num & (ulong)-1);
            int  num6 = (int)(num >> 32 & (ulong)-1);
            int  num7 = (int)num1;
            bool flag = (num2 & 1) == 1;
            byte num8 = (byte)((num2 & 510) >> 1);

            return(new decimal(num5, num6, num7, flag, num8));
        }
コード例 #6
0
ファイル: ProtoReader.cs プロジェクト: yonglehou/Symbiote
        /// <summary>
        /// Reads (merges) a sub-message from the stream, internally calling StartSubItem and EndSubItem, and (in between)
        /// parsing the message in accordance with the model associated with the reader
        /// </summary>
        public static object ReadObject(object value, int key, ProtoReader reader)
        {
            if (reader.model == null)
            {
                throw AddErrorData(new InvalidOperationException("Cannot deserialize sub-objects unless a model is provided"), reader);
            }
            SubItemToken token = ProtoReader.StartSubItem(reader);

            value = reader.model.Deserialize(key, value, reader);
            ProtoReader.EndSubItem(token, reader);
            return(value);
        }
コード例 #7
0
        public static Guid ReadGuid(ProtoReader source)
        {
            ulong        num          = (ulong)0;
            ulong        num1         = (ulong)0;
            SubItemToken subItemToken = ProtoReader.StartSubItem(source);

            while (true)
            {
                int num2 = source.ReadFieldHeader();
                int num3 = num2;
                if (num2 <= 0)
                {
                    break;
                }
                switch (num3)
                {
                case 1:
                {
                    num = source.ReadUInt64();
                    continue;
                }

                case 2:
                {
                    num1 = source.ReadUInt64();
                    continue;
                }

                default:
                {
                    source.SkipField();
                    continue;
                }
                }
            }
            ProtoReader.EndSubItem(subItemToken, source);
            if (num == (long)0 && num1 == (long)0)
            {
                return(Guid.Empty);
            }
            uint num4 = (uint)(num >> 32);
            uint num5 = (uint)num;
            uint num6 = (uint)(num1 >> 32);
            uint num7 = (uint)num1;

            return(new Guid((int)num5, (short)num4, (short)(num4 >> 16), (byte)num7, (byte)(num7 >> 8), (byte)(num7 >> 16), (byte)(num7 >> 24), (byte)num6, (byte)(num6 >> 8), (byte)(num6 >> 16), (byte)(num6 >> 24)));
        }
コード例 #8
0
ファイル: ProtoReader.cs プロジェクト: unseen-code/tianqi_src
        internal static object ReadTypedObject(object value, int key, ProtoReader reader, Type type)
        {
            if (reader.model == null)
            {
                throw ProtoReader.AddErrorData(new InvalidOperationException("Cannot deserialize sub-objects unless a model is provided"), reader);
            }
            SubItemToken token = ProtoReader.StartSubItem(reader);

            if (key >= 0)
            {
                value = reader.model.Deserialize(key, value, reader);
            }
            else if (type == null || !reader.model.TryDeserializeAuxiliaryType(reader, DataFormat.Default, 1, type, ref value, true, false, true, false))
            {
                TypeModel.ThrowUnexpectedType(type);
            }
            ProtoReader.EndSubItem(token, reader);
            return(value);
        }
コード例 #9
0
ファイル: BclHelpers.cs プロジェクト: x1234xx/Mystery_Stealer
        public static decimal ReadDecimal(ProtoReader reader)
        {
            ulong        num   = 0uL;
            uint         num2  = 0u;
            uint         num3  = 0u;
            SubItemToken token = ProtoReader.StartSubItem(reader);
            int          num4;

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

                case 2:
                    num2 = reader.ReadUInt32();
                    break;

                case 3:
                    num3 = reader.ReadUInt32();
                    break;

                default:
                    reader.SkipField();
                    break;
                }
            }
            ProtoReader.EndSubItem(token, reader);
            if (num == 0L && num2 == 0)
            {
                return(0m);
            }
            int  lo         = (int)(num & uint.MaxValue);
            int  mid        = (int)((num >> 32) & uint.MaxValue);
            int  hi         = (int)num2;
            bool isNegative = (num3 & 1) == 1;
            byte scale      = (byte)((num3 & 0x1FE) >> 1);

            return(new decimal(lo, mid, hi, isNegative, scale));
        }
コード例 #10
0
        public static decimal ReadDecimal(ProtoReader reader)
        {
            ulong        num   = 0uL;
            uint         num2  = 0u;
            uint         num3  = 0u;
            SubItemToken token = ProtoReader.StartSubItem(reader);
            int          num4;

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

                case 2:
                    num2 = reader.ReadUInt32();
                    break;

                case 3:
                    num3 = reader.ReadUInt32();
                    break;

                default:
                    reader.SkipField();
                    break;
                }
            }
            ProtoReader.EndSubItem(token, reader);
            if (num == 0uL && num2 == 0u)
            {
                return(0m);
            }
            int  num5 = (int)(num & (ulong)-1);
            int  num6 = (int)(num >> 32 & (ulong)-1);
            int  num7 = (int)num2;
            bool flag = (num3 & 1u) == 1u;
            byte b    = (byte)((num3 & 510u) >> 1);

            return(new decimal(num5, num6, num7, flag, b));
        }
コード例 #11
0
        public static Guid ReadGuid(ProtoReader source)
        {
            ulong        num   = 0uL;
            ulong        num2  = 0uL;
            SubItemToken token = ProtoReader.StartSubItem(source);
            int          num3;

            while ((num3 = source.ReadFieldHeader()) > 0)
            {
                int num4 = num3;
                if (num4 != 1)
                {
                    if (num4 != 2)
                    {
                        source.SkipField();
                    }
                    else
                    {
                        num2 = source.ReadUInt64();
                    }
                }
                else
                {
                    num = source.ReadUInt64();
                }
            }
            ProtoReader.EndSubItem(token, source);
            if (num == 0uL && num2 == 0uL)
            {
                return(Guid.Empty);
            }
            uint num5 = (uint)(num >> 32);
            uint num6 = (uint)num;
            uint num7 = (uint)(num2 >> 32);
            uint num8 = (uint)num2;

            return(new Guid((int)num6, (short)num5, (short)(num5 >> 16), (byte)num8, (byte)(num8 >> 8), (byte)(num8 >> 16), (byte)(num8 >> 24), (byte)num7, (byte)(num7 >> 8), (byte)(num7 >> 16), (byte)(num7 >> 24)));
        }
コード例 #12
0
ファイル: ProtoReader.cs プロジェクト: unseen-code/tianqi_src
        private void AppendExtensionField(ProtoWriter writer)
        {
            ProtoWriter.WriteFieldHeader(this.fieldNumber, this.wireType, writer);
            WireType wireType = this.wireType;

            switch (wireType + 1)
            {
            case WireType.Fixed64:
            case WireType.String:
            case (WireType)9:
                ProtoWriter.WriteInt64(this.ReadInt64(), writer);
                return;

            case WireType.StartGroup:
                ProtoWriter.WriteBytes(ProtoReader.AppendBytes(null, this), writer);
                return;

            case WireType.EndGroup:
            {
                SubItemToken token  = ProtoReader.StartSubItem(this);
                SubItemToken token2 = ProtoWriter.StartSubItem(null, writer);
                while (this.ReadFieldHeader() > 0)
                {
                    this.AppendExtensionField(writer);
                }
                ProtoReader.EndSubItem(token, this);
                ProtoWriter.EndSubItem(token2, writer);
                return;
            }

            case (WireType)6:
                ProtoWriter.WriteInt32(this.ReadInt32(), writer);
                return;
            }
            throw this.CreateWireTypeException();
        }
コード例 #13
0
ファイル: BclHelpers.cs プロジェクト: x1234xx/Mystery_Stealer
        public static Guid ReadGuid(ProtoReader source)
        {
            ulong        num   = 0uL;
            ulong        num2  = 0uL;
            SubItemToken token = ProtoReader.StartSubItem(source);
            int          num3;

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

                case 2:
                    num2 = source.ReadUInt64();
                    break;

                default:
                    source.SkipField();
                    break;
                }
            }
            ProtoReader.EndSubItem(token, source);
            if (num == 0L && num2 == 0L)
            {
                return(Guid.Empty);
            }
            uint num4 = (uint)(num >> 32);
            int  a    = (int)num;
            uint num5 = (uint)(num2 >> 32);
            uint num6 = (uint)num2;

            return(new Guid(a, (short)num4, (short)(num4 >> 16), (byte)num6, (byte)(num6 >> 8), (byte)(num6 >> 16), (byte)(num6 >> 24), (byte)num5, (byte)(num5 >> 8), (byte)(num5 >> 16), (byte)(num5 >> 24)));
        }
コード例 #14
0
        /// <summary>
        /// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
        /// </summary>
        public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
        {
            SubItemToken token = ProtoReader.StartSubItem(source);
            int          fieldNumber;
            int          newObjectKey = -1, newTypeKey = -1, tmp;

            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                case FieldExistingObjectKey:
                    tmp   = source.ReadInt32();
                    value = source.NetCache.GetKeyedObject(tmp);
                    break;

                case FieldNewObjectKey:
                    newObjectKey = source.ReadInt32();
                    break;

                case FieldExistingTypeKey:
                    tmp  = source.ReadInt32();
                    type = (Type)source.NetCache.GetKeyedObject(tmp);
                    key  = source.GetTypeKey(ref type);
                    break;

                case FieldNewTypeKey:
                    newTypeKey = source.ReadInt32();
                    break;

                case FieldTypeName:
                    string typeName = source.ReadString();
                    type = source.DeserializeType(typeName);
                    if (type == null)
                    {
                        throw new ProtoException("Unable to resolve type: " + typeName + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
                    }
                    key = source.GetTypeKey(ref type);
                    if (key < 0)
                    {
                        throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                    }
                    break;

                case FieldObject:
                    bool isString = type == typeof(string);
                    bool lateSet  = value == null && isString;
                    if (value == null && !lateSet)
                    {
                        try
                        {
                            value = ((options & NetObjectOptions.UseConstructor) == 0)
                                            ? BclHelpers.GetUninitializedObject(type)
                                            : Activator.CreateInstance(type);
                        } catch (Exception ex)
                        {
                            throw new ProtoException("Unable to create type " + (type == null ? "<null>" : type.FullName) + ": " + ex.Message, ex);
                        }
                    }
                    if (newObjectKey >= 0 && !lateSet)
                    {
                        source.NetCache.SetKeyedObject(newObjectKey, value);
                        if (newTypeKey >= 0)
                        {
                            source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                    }
                    object oldValue = value;
                    if (isString)
                    {
                        value = source.ReadString();
                    }
                    else
                    {
                        value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
                    }

                    if (newObjectKey >= 0 && lateSet)
                    {
                        source.NetCache.SetKeyedObject(newObjectKey, value);
                        if (newTypeKey >= 0)
                        {
                            source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                    }
                    if (newObjectKey >= 0 && !lateSet && !ReferenceEquals(oldValue, value))
                    {
                        throw new ProtoException("A reference-tracked object changed reference during deserialization");
                    }
                    if (newObjectKey < 0 && newTypeKey >= 0)
                    {      // have a new type, but not a new object
                        source.NetCache.SetKeyedObject(newTypeKey, type);
                    }
                    break;

                default:
                    source.SkipField();
                    break;
                }
            }
            if (newObjectKey >= 0 && (options & NetObjectOptions.AsReference) == 0)
            {
                throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
            }
            ProtoReader.EndSubItem(token, source);

            return(value);
        }
コード例 #15
0
ファイル: BclHelpers.cs プロジェクト: x1234xx/Mystery_Stealer
        public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
        {
            SubItemToken token = ProtoReader.StartSubItem(source);
            int          num   = -1;
            int          num2  = -1;
            int          num3;

            while ((num3 = source.ReadFieldHeader()) > 0)
            {
                switch (num3)
                {
                case 1:
                {
                    int key2 = source.ReadInt32();
                    value = source.NetCache.GetKeyedObject(key2);
                    break;
                }

                case 2:
                    num = source.ReadInt32();
                    break;

                case 3:
                {
                    int key2 = source.ReadInt32();
                    type = (Type)source.NetCache.GetKeyedObject(key2);
                    key  = source.GetTypeKey(ref type);
                    break;
                }

                case 4:
                    num2 = source.ReadInt32();
                    break;

                case 8:
                {
                    string text = source.ReadString();
                    type = source.DeserializeType(text);
                    if (type == null)
                    {
                        throw new ProtoException("Unable to resolve type: " + text + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
                    }
                    if (type == typeof(string))
                    {
                        key = -1;
                        break;
                    }
                    key = source.GetTypeKey(ref type);
                    if (key >= 0)
                    {
                        break;
                    }
                    throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                }

                case 10:
                {
                    bool flag  = type == typeof(string);
                    bool flag2 = value == null;
                    bool flag3 = flag2 && (flag || (options & NetObjectOptions.LateSet) != 0);
                    if (num >= 0 && !flag3)
                    {
                        if (value == null)
                        {
                            source.TrapNextObject(num);
                        }
                        else
                        {
                            source.NetCache.SetKeyedObject(num, value);
                        }
                        if (num2 >= 0)
                        {
                            source.NetCache.SetKeyedObject(num2, type);
                        }
                    }
                    object obj = value;
                    value = ((!flag) ? ProtoReader.ReadTypedObject(obj, key, source, type) : source.ReadString());
                    if (num >= 0)
                    {
                        if (flag2 && !flag3)
                        {
                            obj = source.NetCache.GetKeyedObject(num);
                        }
                        if (flag3)
                        {
                            source.NetCache.SetKeyedObject(num, value);
                            if (num2 >= 0)
                            {
                                source.NetCache.SetKeyedObject(num2, type);
                            }
                        }
                    }
                    if (num >= 0 && !flag3 && obj != value)
                    {
                        throw new ProtoException("A reference-tracked object changed reference during deserialization");
                    }
                    if (num < 0 && num2 >= 0)
                    {
                        source.NetCache.SetKeyedObject(num2, type);
                    }
                    break;
                }

                default:
                    source.SkipField();
                    break;
                }
            }
            if (num >= 0 && (options & NetObjectOptions.AsReference) == 0)
            {
                throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
            }
            ProtoReader.EndSubItem(token, source);
            return(value);
        }
コード例 #16
0
ファイル: BclHelpers.cs プロジェクト: x1234xx/Mystery_Stealer
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            switch (source.WireType)
            {
            case WireType.String:
            case WireType.StartGroup:
            {
                SubItemToken  token         = ProtoReader.StartSubItem(source);
                TimeSpanScale timeSpanScale = TimeSpanScale.Days;
                long          num           = 0L;
                int           num2;
                while ((num2 = source.ReadFieldHeader()) > 0)
                {
                    switch (num2)
                    {
                    case 2:
                        timeSpanScale = (TimeSpanScale)source.ReadInt32();
                        break;

                    case 1:
                        source.Assert(WireType.SignedVariant);
                        num = source.ReadInt64();
                        break;

                    default:
                        source.SkipField();
                        break;
                    }
                }
                ProtoReader.EndSubItem(token, source);
                switch (timeSpanScale)
                {
                case TimeSpanScale.Days:
                    return(num * 864000000000L);

                case TimeSpanScale.Hours:
                    return(num * 36000000000L);

                case TimeSpanScale.Minutes:
                    return(num * 600000000);

                case TimeSpanScale.Seconds:
                    return(num * 10000000);

                case TimeSpanScale.Milliseconds:
                    return(num * 10000);

                case TimeSpanScale.Ticks:
                    return(num);

                case TimeSpanScale.MinMax:
                    switch (num)
                    {
                    case 1L:
                        return(long.MaxValue);

                    case -1L:
                        return(long.MinValue);

                    default:
                        throw new ProtoException("Unknown min/max value: " + num);
                    }

                default:
                    throw new ProtoException("Unknown timescale: " + timeSpanScale);
                }
            }

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

            default:
                throw new ProtoException("Unexpected wire-type: " + source.WireType);
            }
        }
コード例 #17
0
        /// <summary>
        /// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
        /// </summary>
        public static object ReadNetObject(object value, ProtoReader source, int key, Type type)
        {
            SubItemToken token = ProtoReader.StartSubItem(source);
            int          fieldNumber;
            int          newObjectKey = -1, newTypeKey = -1, tmp;

            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                case FieldExistingObjectKey:
                    tmp   = source.ReadInt32();
                    value = source.NetCache.GetKeyedObject(tmp);
                    break;

                case FieldNewObjectKey:
                    newObjectKey = source.ReadInt32();
                    break;

                case FieldExistingTypeKey:
                    tmp  = source.ReadInt32();
                    type = (Type)source.NetCache.GetKeyedObject(tmp);
                    key  = source.GetTypeKey(ref type);
                    break;

                case FieldNewTypeKey:
                    newTypeKey = source.ReadInt32();
                    break;

                case FieldTypeName:
                    type = source.DeserializeType(source.ReadString());
                    key  = source.GetTypeKey(ref type);
                    break;

                case FieldObject:
                    bool isString = type == typeof(string);
                    bool lateSet  = value == null && isString;
                    if (value == null && !lateSet)
                    {
                        value = Activator.CreateInstance(type);                                // TODO wcf-style inits
                    }
                    if (newObjectKey >= 0 && !lateSet)
                    {
                        source.NetCache.SetKeyedObject(newObjectKey, value);
                        if (newTypeKey >= 0)
                        {
                            source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                    }
                    object oldValue = value;
                    if (isString)
                    {
                        value = source.ReadString();
                    }
                    else
                    {
                        value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
                    }

                    if (newObjectKey >= 0 && lateSet)
                    {
                        source.NetCache.SetKeyedObject(newObjectKey, value);
                        if (newTypeKey >= 0)
                        {
                            source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                    }
                    if (!lateSet && !ReferenceEquals(oldValue, value))
                    {
                        throw new ProtoException("A reference-tracked object changed reference during deserialization");
                    }
                    break;

                default:
                    source.SkipField();
                    break;
                }
            }
            ProtoReader.EndSubItem(token, source);

            return(value);
        }
コード例 #18
0
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            switch (source.WireType)
            {
            case WireType.Fixed64:
                return(source.ReadInt64());

            case WireType.String:
            case WireType.StartGroup:
            {
                SubItemToken  token         = ProtoReader.StartSubItem(source);
                TimeSpanScale timeSpanScale = TimeSpanScale.Days;
                long          num           = 0L;
                int           num2;
                while ((num2 = source.ReadFieldHeader()) > 0)
                {
                    int num3 = num2;
                    if (num3 != 1)
                    {
                        if (num3 != 2)
                        {
                            source.SkipField();
                        }
                        else
                        {
                            timeSpanScale = (TimeSpanScale)source.ReadInt32();
                        }
                    }
                    else
                    {
                        source.Assert(WireType.SignedVariant);
                        num = source.ReadInt64();
                    }
                }
                ProtoReader.EndSubItem(token, source);
                TimeSpanScale timeSpanScale2 = timeSpanScale;
                switch (timeSpanScale2)
                {
                case TimeSpanScale.Days:
                    return(num * 864000000000L);

                case TimeSpanScale.Hours:
                    return(num * 36000000000L);

                case TimeSpanScale.Minutes:
                    return(num * 600000000L);

                case TimeSpanScale.Seconds:
                    return(num * 10000000L);

                case TimeSpanScale.Milliseconds:
                    return(num * 10000L);

                case TimeSpanScale.Ticks:
                    return(num);

                default:
                {
                    if (timeSpanScale2 != TimeSpanScale.MinMax)
                    {
                        throw new ProtoException("Unknown timescale: " + timeSpanScale.ToString());
                    }
                    long num4 = num;
                    if (num4 >= -1L && num4 <= 1L)
                    {
                        switch ((int)(num4 - -1L))
                        {
                        case 0:
                            return(-9223372036854775808L);

                        case 2:
                            return(9223372036854775807L);
                        }
                    }
                    throw new ProtoException("Unknown min/max value: " + num.ToString());
                }
                }
                break;
            }

            default:
                throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
            }
        }
コード例 #19
0
        private static long ReadTimeSpanTicks(ProtoReader source, out DateTimeKind kind)
        {
            kind = DateTimeKind.Unspecified;
            switch (source.WireType)
            {
            case WireType.String:
            case WireType.StartGroup:
                SubItemToken  token = ProtoReader.StartSubItem(source);
                int           fieldNumber;
                TimeSpanScale scale = TimeSpanScale.Days;
                long          value = 0;
                while ((fieldNumber = source.ReadFieldHeader()) > 0)
                {
                    switch (fieldNumber)
                    {
                    case FieldTimeSpanScale:
                        scale = (TimeSpanScale)source.ReadInt32();
                        break;

                    case FieldTimeSpanValue:
                        source.Assert(WireType.SignedVariant);
                        value = source.ReadInt64();
                        break;

                    case FieldTimeSpanKind:
                        kind = (DateTimeKind)source.ReadInt32();
                        switch (kind)
                        {
                        case DateTimeKind.Unspecified:
                        case DateTimeKind.Utc:
                        case DateTimeKind.Local:
                            break;             // fine

                        default:
                            throw new ProtoException("Invalid date/time kind: " + kind.ToString());
                        }
                        break;

                    default:
                        source.SkipField();
                        break;
                    }
                }
                ProtoReader.EndSubItem(token, source);
                switch (scale)
                {
                case TimeSpanScale.Days:
                    return(value * TimeSpan.TicksPerDay);

                case TimeSpanScale.Hours:
                    return(value * TimeSpan.TicksPerHour);

                case TimeSpanScale.Minutes:
                    return(value * TimeSpan.TicksPerMinute);

                case TimeSpanScale.Seconds:
                    return(value * TimeSpan.TicksPerSecond);

                case TimeSpanScale.Milliseconds:
                    return(value * TimeSpan.TicksPerMillisecond);

                case TimeSpanScale.Ticks:
                    return(value);

                case TimeSpanScale.MinMax:
                    switch (value)
                    {
                    case 1: return(long.MaxValue);

                    case -1: return(long.MinValue);

                    default: throw new ProtoException("Unknown min/max value: " + value.ToString());
                    }

                default:
                    throw new ProtoException("Unknown timescale: " + scale.ToString());
                }

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

            default:
                throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
            }
        }
コード例 #20
0
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            TimeSpanScale timeSpanScale;

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

            case WireType.String:
            case WireType.StartGroup:
            {
                SubItemToken subItemToken = ProtoReader.StartSubItem(source);
                timeSpanScale = TimeSpanScale.Days;
                long num = (long)0;
                while (true)
                {
                    int num1 = source.ReadFieldHeader();
                    int num2 = num1;
                    if (num1 <= 0)
                    {
                        break;
                    }
                    switch (num2)
                    {
                    case 1:
                    {
                        source.Assert(WireType.SignedVariant);
                        num = source.ReadInt64();
                        continue;
                    }

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

                    default:
                    {
                        source.SkipField();
                        continue;
                    }
                    }
                }
                ProtoReader.EndSubItem(subItemToken, source);
                TimeSpanScale timeSpanScale1 = timeSpanScale;
                switch (timeSpanScale1)
                {
                case TimeSpanScale.Days:
                {
                    return(num * 864000000000L);
                }

                case TimeSpanScale.Hours:
                {
                    return(num * 36000000000L);
                }

                case TimeSpanScale.Minutes:
                {
                    return(num * (long)600000000);
                }

                case TimeSpanScale.Seconds:
                {
                    return(num * (long)10000000);
                }

                case TimeSpanScale.Milliseconds:
                {
                    return(num * (long)10000);
                }

                case TimeSpanScale.Ticks:
                {
                    return(num);
                }

                default:
                {
                    if (timeSpanScale1 == TimeSpanScale.MinMax)
                    {
                        break;
                    }
                    else
                    {
                        throw new ProtoException(string.Concat("Unknown timescale: ", timeSpanScale.ToString()));
                    }
                }
                }
                long num3 = num;
                if (num3 <= (long)1 && num3 >= (long)-1)
                {
                    switch ((int)(num3 - (long)-1))
                    {
                    case 0:
                    {
                        return(-9223372036854775808L);
                    }

                    case 2:
                    {
                        return(9223372036854775807L);
                    }
                    }
                }
                throw new ProtoException(string.Concat("Unknown min/max value: ", num.ToString()));
            }
            }
            throw new ProtoException(string.Concat("Unexpected wire-type: ", source.WireType.ToString()));
            throw new ProtoException(string.Concat("Unknown timescale: ", timeSpanScale.ToString()));
        }
コード例 #21
0
        public static object ReadNetObject(object value, ProtoReader source, int key, Type type, BclHelpers.NetObjectOptions options)
        {
            int          num;
            bool         flag;
            SubItemToken subItemToken = ProtoReader.StartSubItem(source);
            int          num1         = -1;
            int          num2         = -1;

            do
            {
Label0:
                int num3 = source.ReadFieldHeader();
                int num4 = num3;
                if (num3 <= 0)
                {
                    if (num1 >= 0 && (byte)(options & BclHelpers.NetObjectOptions.AsReference) == 0)
                    {
                        throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
                    }
                    ProtoReader.EndSubItem(subItemToken, source);
                    return(value);
                }
                switch (num4)
                {
                case 1:
                {
                    num   = source.ReadInt32();
                    value = source.NetCache.GetKeyedObject(num);
                    goto Label0;
                }

                case 2:
                {
                    num1 = source.ReadInt32();
                    goto Label0;
                }

                case 3:
                {
                    num  = source.ReadInt32();
                    type = (Type)source.NetCache.GetKeyedObject(num);
                    key  = source.GetTypeKey(ref type);
                    goto Label0;
                }

                case 4:
                {
                    num2 = source.ReadInt32();
                    goto Label0;
                }

                case 5:
                case 6:
                case 7:
                case 9:
                {
                    source.SkipField();
                    goto Label0;
                }

                case 8:
                {
                    string str = source.ReadString();
                    type = source.DeserializeType(str);
                    if (type == null)
                    {
                        throw new ProtoException(string.Concat("Unable to resolve type: ", str, " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)"));
                    }
                    if (type != typeof(string))
                    {
                        key = source.GetTypeKey(ref type);
                        continue;
                    }
                    else
                    {
                        key = -1;
                        goto Label0;
                    }
                }

                case 10:
                {
                    bool flag1 = type == typeof(string);
                    bool flag2 = value == null;
                    if (!flag2)
                    {
                        flag = false;
                    }
                    else
                    {
                        flag = (flag1 ? true : (byte)(options & BclHelpers.NetObjectOptions.LateSet) != 0);
                    }
                    bool flag3 = flag;
                    if (num1 >= 0 && !flag3)
                    {
                        if (value != null)
                        {
                            source.NetCache.SetKeyedObject(num1, value);
                        }
                        else
                        {
                            source.TrapNextObject(num1);
                        }
                        if (num2 >= 0)
                        {
                            source.NetCache.SetKeyedObject(num2, type);
                        }
                    }
                    object keyedObject = value;
                    if (!flag1)
                    {
                        value = ProtoReader.ReadTypedObject(keyedObject, key, source, type);
                    }
                    else
                    {
                        value = source.ReadString();
                    }
                    if (num1 >= 0)
                    {
                        if (flag2 && !flag3)
                        {
                            keyedObject = source.NetCache.GetKeyedObject(num1);
                        }
                        if (flag3)
                        {
                            source.NetCache.SetKeyedObject(num1, value);
                            if (num2 >= 0)
                            {
                                source.NetCache.SetKeyedObject(num2, type);
                            }
                        }
                    }
                    if (num1 >= 0 && !flag3 && !object.ReferenceEquals(keyedObject, value))
                    {
                        throw new ProtoException("A reference-tracked object changed reference during deserialization");
                    }
                    if (num1 >= 0 || num2 < 0)
                    {
                        goto Label0;
                    }
                    source.NetCache.SetKeyedObject(num2, type);
                    goto Label0;
                }

                default:
                {
                    goto case 9;
                }
                }
            }while (key >= 0);
            throw new InvalidOperationException(string.Concat("Dynamic type is not a contract-type: ", type.Name));
        }
コード例 #22
0
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            WireType wireType = source.WireType;

            if (wireType != WireType.Fixed64)
            {
                if ((uint)(wireType - 2) <= 1u)
                {
                    SubItemToken  token         = ProtoReader.StartSubItem(source);
                    TimeSpanScale timeSpanScale = TimeSpanScale.Days;
                    long          num           = 0L;
                    int           num2;
                    while ((num2 = source.ReadFieldHeader()) > 0)
                    {
                        switch (num2)
                        {
                        case 2:
                            timeSpanScale = (TimeSpanScale)source.ReadInt32();
                            break;

                        case 1:
                            source.Assert(WireType.SignedVariant);
                            num = source.ReadInt64();
                            break;

                        default:
                            source.SkipField();
                            break;
                        }
                    }
                    ProtoReader.EndSubItem(token, source);
                    switch (timeSpanScale)
                    {
                    case TimeSpanScale.Days:
                        return(num * 864000000000L);

                    case TimeSpanScale.Hours:
                        return(num * 36000000000L);

                    case TimeSpanScale.Minutes:
                        return(num * 600000000);

                    case TimeSpanScale.Seconds:
                        return(num * 10000000);

                    case TimeSpanScale.Milliseconds:
                        return(num * 10000);

                    case TimeSpanScale.Ticks:
                        return(num);

                    case TimeSpanScale.MinMax:
                        switch (num)
                        {
                        case 1L:
                            return(9223372036854775807L);

                        case -1L:
                            return(-9223372036854775808L);

                        default:
                            throw new ProtoException("Unknown min/max value: " + num.ToString());
                        }

                    default:
                        throw new ProtoException("Unknown timescale: " + timeSpanScale.ToString());
                    }
                }
                wireType = source.WireType;
                throw new ProtoException("Unexpected wire-type: " + wireType.ToString());
            }
            return(source.ReadInt64());
        }
コード例 #23
0
        // Token: 0x06003269 RID: 12905 RVA: 0x001266EC File Offset: 0x00124AEC
        private static long ReadTimeSpanTicks(ProtoReader source, out DateTimeKind kind)
        {
            kind = DateTimeKind.Unspecified;
            switch (source.WireType)
            {
            case WireType.Fixed64:
                return(source.ReadInt64());

            case WireType.String:
            case WireType.StartGroup:
            {
                SubItemToken  token         = ProtoReader.StartSubItem(source);
                TimeSpanScale timeSpanScale = TimeSpanScale.Days;
                long          num           = 0L;
                int           num2;
                while ((num2 = source.ReadFieldHeader()) > 0)
                {
                    switch (num2)
                    {
                    case 1:
                        source.Assert(WireType.SignedVariant);
                        num = source.ReadInt64();
                        break;

                    case 2:
                        timeSpanScale = (TimeSpanScale)source.ReadInt32();
                        break;

                    case 3:
                        kind = (DateTimeKind)source.ReadInt32();
                        switch (kind)
                        {
                        case DateTimeKind.Unspecified:
                        case DateTimeKind.Utc:
                        case DateTimeKind.Local:
                            break;

                        default:
                            throw new ProtoException("Invalid date/time kind: " + kind.ToString());
                        }
                        break;

                    default:
                        source.SkipField();
                        break;
                    }
                }
                ProtoReader.EndSubItem(token, source);
                switch (timeSpanScale)
                {
                case TimeSpanScale.Days:
                    return(num * 864000000000L);

                case TimeSpanScale.Hours:
                    return(num * 36000000000L);

                case TimeSpanScale.Minutes:
                    return(num * 600000000L);

                case TimeSpanScale.Seconds:
                    return(num * 10000000L);

                case TimeSpanScale.Milliseconds:
                    return(num * 10000L);

                case TimeSpanScale.Ticks:
                    return(num);

                default:
                    if (timeSpanScale != TimeSpanScale.MinMax)
                    {
                        throw new ProtoException("Unknown timescale: " + timeSpanScale.ToString());
                    }
                    if (num == 1L)
                    {
                        return(long.MaxValue);
                    }
                    if (num != -1L)
                    {
                        throw new ProtoException("Unknown min/max value: " + num.ToString());
                    }
                    return(long.MinValue);
                }
            }

            default:
                throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
            }
        }
コード例 #24
0
        /// <summary>
        /// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
        /// </summary>
        public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
        {
#if FEAT_IKVM
            throw new NotSupportedException();
#else
            SubItemToken token = ProtoReader.StartSubItem(source);
            int          fieldNumber;
            int          newObjectKey = -1, newTypeKey = -1, tmp;
            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                case FieldExistingObjectKey:
                    tmp   = source.ReadInt32();
                    value = source.NetCache.GetKeyedObject(tmp);
                    break;

                case FieldNewObjectKey:
                    newObjectKey = source.ReadInt32();
                    break;

                case FieldExistingTypeKey:
                    tmp  = source.ReadInt32();
                    type = (Type)source.NetCache.GetKeyedObject(tmp);
                    key  = source.GetTypeKey(ref type);
                    break;

                case FieldNewTypeKey:
                    newTypeKey = source.ReadInt32();
                    break;

                case FieldTypeName:
                    string typeName = source.ReadString();
                    type = source.DeserializeType(typeName);
                    if (type == null)
                    {
                        throw new ProtoException("Unable to resolve type: " + typeName + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
                    }
                    if (type == typeof(string))
                    {
                        key = -1;
                    }
                    else
                    {
                        key = source.GetTypeKey(ref type);
                        if (key < 0)
                        {
                            throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                        }
                    }
                    break;

                case FieldObject:
                    bool isString = type == typeof(string);
                    bool wasNull  = value == null;
                    bool lateSet  = wasNull && (isString || ((options & NetObjectOptions.LateSet) != 0));

                    if (newObjectKey >= 0 && !lateSet)
                    {
                        if (value == null)
                        {
                            source.TrapNextObject(newObjectKey);
                        }
                        else
                        {
                            source.NetCache.SetKeyedObject(newObjectKey, value);
                        }
                        if (newTypeKey >= 0)
                        {
                            source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                    }
                    object oldValue = value;
                    if (isString)
                    {
                        value = source.ReadString();
                    }
                    else
                    {
                        value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
                    }

                    if (newObjectKey >= 0)
                    {
                        if (wasNull && !lateSet)
                        {     // this both ensures (via exception) that it *was* set, and makes sure we don't shout
                            // about changed references
                            oldValue = source.NetCache.GetKeyedObject(newObjectKey);
                        }
                        if (lateSet)
                        {
                            source.NetCache.SetKeyedObject(newObjectKey, value);
                            if (newTypeKey >= 0)
                            {
                                source.NetCache.SetKeyedObject(newTypeKey, type);
                            }
                        }
                    }
                    if (newObjectKey >= 0 && !lateSet && !ReferenceEquals(oldValue, value))
                    {
                        throw new ProtoException("A reference-tracked object changed reference during deserialization");
                    }
                    if (newObjectKey < 0 && newTypeKey >= 0)
                    {      // have a new type, but not a new object
                        source.NetCache.SetKeyedObject(newTypeKey, type);
                    }
                    break;

                default:
                    source.SkipField();
                    break;
                }
            }
            if (newObjectKey >= 0 && (options & NetObjectOptions.AsReference) == 0)
            {
                throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
            }
            ProtoReader.EndSubItem(token, source);

            return(value);
#endif
        }
コード例 #25
0
        // Token: 0x06000039 RID: 57 RVA: 0x0000A274 File Offset: 0x00008474
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            WireType wireType = source.WireType;

            if (wireType == WireType.Fixed64)
            {
                return(source.ReadInt64());
            }
            if (wireType - WireType.String > 1)
            {
                throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
            }
            SubItemToken  token         = ProtoReader.StartSubItem(source);
            TimeSpanScale timeSpanScale = TimeSpanScale.Days;
            long          num           = 0L;
            int           num2;

            while ((num2 = source.ReadFieldHeader()) > 0)
            {
                if (num2 != 1)
                {
                    if (num2 == 2)
                    {
                        timeSpanScale = (TimeSpanScale)source.ReadInt32();
                    }
                    else
                    {
                        source.SkipField();
                    }
                }
                else
                {
                    source.Assert(WireType.SignedVariant);
                    num = source.ReadInt64();
                }
            }
            ProtoReader.EndSubItem(token, source);
            switch (timeSpanScale)
            {
            case TimeSpanScale.Days:
                return(num * 864000000000L);

            case TimeSpanScale.Hours:
                return(num * 36000000000L);

            case TimeSpanScale.Minutes:
                return(num * 600000000L);

            case TimeSpanScale.Seconds:
                return(num * 10000000L);

            case TimeSpanScale.Milliseconds:
                return(num * 10000L);

            case TimeSpanScale.Ticks:
                return(num);

            default:
                if (timeSpanScale != TimeSpanScale.MinMax)
                {
                    throw new ProtoException("Unknown timescale: " + timeSpanScale.ToString());
                }
                if (num == -1L)
                {
                    return(long.MinValue);
                }
                if (num == 1L)
                {
                    return(long.MaxValue);
                }
                throw new ProtoException("Unknown min/max value: " + num.ToString());
            }
        }