Exemplo n.º 1
0
        private static TimeSpan ReadDurationFallback(ProtoReader source, ref ProtoReader.State state)
        {
            long         seconds = 0;
            int          nanos   = 0;
            SubItemToken token   = ProtoReader.StartSubItem(source, ref state);
            int          fieldNumber;

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

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

                default:
                    source.SkipField(ref state);
                    break;
                }
            }
            ProtoReader.EndSubItem(token, source, ref state);
            return(FromDurationSeconds(seconds, nanos));
        }
Exemplo n.º 2
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());
            }
        }
Exemplo n.º 3
0
 static public int ReadInt32(IntPtr l)
 {
     try {
         ProtoBuf.ProtoReader self = (ProtoBuf.ProtoReader)checkSelf(l);
         var ret = self.ReadInt32();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 4
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:
                        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 = ((options & NetObjectOptions.UseConstructor) == 0) ? BclHelpers.GetUninitializedObject(type) : Activator.CreateInstance(type);
                        }
                        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;
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 private static long ReadTimeSpanTicks(ProtoReader source) {
     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;
                     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());
     }
 }
Exemplo n.º 7
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
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
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()));
        }
Exemplo n.º 10
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));
        }
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="targetPlatform">
        /// The target platform.
        /// </param>
        /// <param name="protoReader">
        /// The proto reader.
        /// </param>
        /// <returns>
        /// The <see cref="TargetPlatform"/>.
        /// </returns>
        private static TargetPlatform Read(TargetPlatform targetPlatform, ProtoReader protoReader)
        {
            int num = protoReader.ReadInt32();
            var result = TargetPlatform.Windows;
            if (num != 0)
            {
                if (num != 1)
                {
                    if (num != 2)
                    {
                        if (num != 3)
                        {
                            if (num != 4)
                            {
                                if (num != 5)
                                {
                                    if (num != 6)
                                    {
                                        if (num != 7)
                                        {
                                            if (num != 8)
                                            {
                                                if (num != 9)
                                                {
                                                    if (num != 10)
                                                    {
                                                        if (num != 11)
                                                        {
                                                            if (num != 12)
                                                            {
                                                                protoReader.ThrowEnumException(
                                                                    typeof(TargetPlatform), 
                                                                    num);
                                                            }
                                                            else
                                                            {
                                                                result = TargetPlatform.RaspberryPi;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            result = TargetPlatform.WindowsPhone8;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        result = TargetPlatform.PlayStationMobile;
                                                    }
                                                }
                                                else
                                                {
                                                    result = TargetPlatform.Ouya;
                                                }
                                            }
                                            else
                                            {
                                                result = TargetPlatform.NativeClient;
                                            }
                                        }
                                        else
                                        {
                                            result = TargetPlatform.WindowsStoreApp;
                                        }
                                    }
                                    else
                                    {
                                        result = TargetPlatform.MacOSX;
                                    }
                                }
                                else
                                {
                                    result = TargetPlatform.Linux;
                                }
                            }
                            else
                            {
                                result = TargetPlatform.Android;
                            }
                        }
                        else
                        {
                            result = TargetPlatform.iOS;
                        }
                    }
                    else
                    {
                        result = TargetPlatform.WindowsPhone;
                    }
                }
                else
                {
                    result = TargetPlatform.Xbox360;
                }
            }
            else
            {
                result = TargetPlatform.Windows;
            }

            return result;
        }
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="platformData">
        /// The platform data.
        /// </param>
        /// <param name="protoReader">
        /// The proto reader.
        /// </param>
        /// <returns>
        /// The <see cref="PlatformData"/>.
        /// </returns>
        private static PlatformData Read(PlatformData platformData, ProtoReader protoReader)
        {
            int num;
            while ((num = protoReader.ReadFieldHeader()) > 0)
            {
                if (num != 1)
                {
                    if (num != 2)
                    {
                        if (platformData == null)
                        {
                            var expr_164 = new PlatformData();
                            ProtoReader.NoteObject(expr_164, protoReader);
                            platformData = expr_164;
                        }

                        protoReader.SkipField();
                    }
                    else
                    {
                        if (platformData == null)
                        {
                            var expr_134 = new PlatformData();
                            ProtoReader.NoteObject(expr_134, protoReader);
                            platformData = expr_134;
                        }

                        byte[] array = ProtoReader.AppendBytes(platformData.Data, protoReader);
                        if (array != null)
                        {
                            platformData.Data = array;
                        }
                    }
                }
                else
                {
                    if (platformData == null)
                    {
                        var expr_19 = new PlatformData();
                        ProtoReader.NoteObject(expr_19, protoReader);
                        platformData = expr_19;
                    }

                    int num2 = protoReader.ReadInt32();
                    var targetPlatform = TargetPlatform.Windows;
                    if (num2 != 0)
                    {
                        if (num2 != 1)
                        {
                            if (num2 != 2)
                            {
                                if (num2 != 3)
                                {
                                    if (num2 != 4)
                                    {
                                        if (num2 != 5)
                                        {
                                            if (num2 != 6)
                                            {
                                                if (num2 != 7)
                                                {
                                                    if (num2 != 8)
                                                    {
                                                        if (num2 != 9)
                                                        {
                                                            if (num2 != 10)
                                                            {
                                                                if (num2 != 11)
                                                                {
                                                                    if (num2 != 12)
                                                                    {
                                                                        protoReader.ThrowEnumException(
                                                                            typeof(TargetPlatform), 
                                                                            num2);
                                                                    }
                                                                    else
                                                                    {
                                                                        targetPlatform = TargetPlatform.RaspberryPi;
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    targetPlatform = TargetPlatform.WindowsPhone8;
                                                                }
                                                            }
                                                            else
                                                            {
                                                                targetPlatform = TargetPlatform.PlayStationMobile;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            targetPlatform = TargetPlatform.Ouya;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        targetPlatform = TargetPlatform.NativeClient;
                                                    }
                                                }
                                                else
                                                {
                                                    targetPlatform = TargetPlatform.WindowsStoreApp;
                                                }
                                            }
                                            else
                                            {
                                                targetPlatform = TargetPlatform.MacOSX;
                                            }
                                        }
                                        else
                                        {
                                            targetPlatform = TargetPlatform.Linux;
                                        }
                                    }
                                    else
                                    {
                                        targetPlatform = TargetPlatform.Android;
                                    }
                                }
                                else
                                {
                                    targetPlatform = TargetPlatform.iOS;
                                }
                            }
                            else
                            {
                                targetPlatform = TargetPlatform.WindowsPhone;
                            }
                        }
                        else
                        {
                            targetPlatform = TargetPlatform.Xbox360;
                        }
                    }
                    else
                    {
                        targetPlatform = TargetPlatform.Windows;
                    }

                    platformData.Platform = targetPlatform;
                }
            }

            if (platformData == null)
            {
                var expr_18C = new PlatformData();
                ProtoReader.NoteObject(expr_18C, protoReader);
                platformData = expr_18C;
            }

            return platformData;
        }
Exemplo n.º 13
0
 private static Product Read(Product product1, ProtoReader reader1)
 {
     int num;
     while ((num = reader1.ReadFieldHeader()) > 0)
     {
         switch (num)
         {
             case 1:
                 if (product1 == null)
                 {
                     product1 = new Product();
                 }
                 product1.ProductID = reader1.ReadInt32();
                 continue;
             case 2:
                 if (product1 == null)
                 {
                     product1 = new Product();
                 }
                 product1.ProductName = reader1.ReadString();
                 continue;
             case 3:
                 if (product1 == null)
                 {
                     product1 = new Product();
                 }
                 product1.SupplierID = new int?(reader1.ReadInt32());
                 continue;
         }
     }
     return product1;
 }
Exemplo n.º 14
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());
            }
        }
Exemplo n.º 15
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());
            }
        }
Exemplo n.º 16
0
        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);
            }
        }
Exemplo n.º 17
0
 object ReadField(ProtoReader reader, Type memberT, string sClassName, CLS_Environment environment)
 {
     if (memberT == typeof(int))
     {
         return reader.ReadInt32();
     }
     else if (memberT == typeof(uint))
     {
         return reader.ReadUInt32();
     }
     else if (memberT == typeof(bool))
     {
         return reader.ReadBoolean();
     }
     else if (memberT == typeof(byte))
     {
         return reader.ReadByte();
     }
     else if (memberT == typeof(sbyte))
     {
         return reader.ReadSByte();
     }
     else if (memberT == typeof(float))
     {
         return reader.ReadSingle();
     }
     else if (memberT == typeof(double))
     {
         return reader.ReadDouble();
     }
     else if (memberT == typeof(short))
     {
         return reader.ReadInt16();
     }
     else if (memberT == typeof(ushort))
     {
         return reader.ReadUInt16();
     }
     else if (memberT == typeof(long))
     {
         return reader.ReadInt64();
     }
     else if (memberT == typeof(ulong))
     {
         return reader.ReadUInt64();
     }
     else if (memberT == typeof(string))
     {
         return reader.ReadString();
     }
     else if (memberT == typeof(byte[]))
     {
         return ProtoReader.AppendBytes(null, reader);
     }
     else if (memberT == typeof(SInstance))
     {
         SubItemToken st = ProtoReader.StartSubItem(reader);
         CLS_Type_Class sClass = environment.GetTypeByKeywordQuiet(sClassName) as CLS_Type_Class;
         if (!sClass.compiled)
             RuntimeCompilerClass(sClassName);
         CLS_Content content = CLS_Content.NewContent(environment);
         CLS_Content.Value retVal = sClass.function.New(content, m_emptyParams);
         CLS_Content.PoolContent(content);
         SInstance sInstance = (SInstance)retVal.value;
         ReadSInstance(reader, sInstance, environment);
         ProtoReader.EndSubItem(st, reader);
         return sInstance;
     }
     else
     {
         throw new NotImplementedException("未实现类型: " + memberT);
     }
 }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
 public static object ReadNetObject(object value, ProtoReader source, int key, Type type, BclHelpers.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);
             continue;
         }
         case 2:
             num = source.ReadInt32();
             continue;
         case 3:
         {
             int key2 = source.ReadInt32();
             type = (Type)source.NetCache.GetKeyedObject(key2);
             key = source.GetTypeKey(ref type);
             continue;
         }
         case 4:
             num2 = source.ReadInt32();
             continue;
         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;
             }
             else
             {
                 key = source.GetTypeKey(ref type);
                 if (key < 0)
                 {
                     throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                 }
             }
             continue;
         }
         case 10:
         {
             bool flag = type == typeof(string);
             bool flag2 = value == null;
             bool flag3 = flag2 && (flag || (byte)(options & BclHelpers.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;
             if (flag)
             {
                 value = source.ReadString();
             }
             else
             {
                 value = ProtoReader.ReadTypedObject(obj, key, source, type);
             }
             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 && !object.ReferenceEquals(obj, value))
             {
                 throw new ProtoException("A reference-tracked object changed reference during deserialization");
             }
             if (num < 0 && num2 >= 0)
             {
                 source.NetCache.SetKeyedObject(num2, type);
             }
             continue;
         }
         }
         source.SkipField();
     }
     if (num >= 0 && (byte)(options & BclHelpers.NetObjectOptions.AsReference) == 0)
     {
         throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
     }
     ProtoReader.EndSubItem(token, source);
     return value;
 }
Exemplo n.º 20
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());
            }
        }
Exemplo n.º 21
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());
     }
 }
        /// <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)
											: (type.IsArray || type.IsInterface ? null : Activator.CreateInstance(type, true));
                            } 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) && type.FullName.StartsWith("System.Collections.Generic.Dictionary`2"))
                        {
                            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;
        }
Exemplo n.º 23
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());
        }
Exemplo n.º 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
        }
Exemplo n.º 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());
            }
        }