ReadValueRaw() public method

public ReadValueRaw ( byte buf, int offset, int count ) : int
buf byte
offset int
count int
return int
Beispiel #1
0
 static object StringUnpacker(ObjectPacker packer, MsgPackReader reader)
 {
     if (!reader.Read())
     {
         throw new FormatException();
     }
     if (reader.Type == TypePrefixes.Nil)
     {
         return(null);
     }
     if (!reader.IsRaw())
     {
         throw new FormatException();
     }
     packer.CheckBufferSize((int)reader.Length);
     reader.ReadValueRaw(packer._buf, 0, (int)reader.Length);
     return(Encoding.UTF8.GetString(packer._buf, 0, (int)reader.Length));
 }
        public object Unpack(MsgPackReader reader)
        {
            //IL_0260: Unknown result type (might be due to invalid IL or missing references)
            //IL_029b: Unknown result type (might be due to invalid IL or missing references)
            //IL_02cb: Unknown result type (might be due to invalid IL or missing references)
            if (reader.Read())
            {
                switch (reader.Type)
                {
                case TypePrefixes.PositiveFixNum:
                case TypePrefixes.Int32:
                case TypePrefixes.NegativeFixNum:
                    return(reader.ValueSigned);

                case TypePrefixes.Int8:
                    return((sbyte)reader.ValueSigned);

                case TypePrefixes.Int16:
                    return((short)reader.ValueSigned);

                case TypePrefixes.Int64:
                    return(reader.ValueSigned64);

                case TypePrefixes.UInt8:
                    return((byte)reader.ValueUnsigned);

                case TypePrefixes.UInt16:
                    return((ushort)reader.ValueUnsigned);

                case TypePrefixes.UInt32:
                    return(reader.ValueUnsigned);

                case TypePrefixes.UInt64:
                    return(reader.ValueUnsigned64);

                case TypePrefixes.True:
                    return(true);

                case TypePrefixes.False:
                    return(false);

                case TypePrefixes.Float:
                    return(reader.ValueFloat);

                case TypePrefixes.Double:
                    return(reader.ValueDouble);

                case TypePrefixes.Nil:
                    return(null);

                case TypePrefixes.FixRaw:
                case TypePrefixes.Raw8:
                case TypePrefixes.Raw16:
                case TypePrefixes.Raw32:
                    return(reader.ReadRawString());

                case TypePrefixes.Bin8:
                case TypePrefixes.Bin16:
                case TypePrefixes.Bin32:
                {
                    byte[] array3 = new byte[reader.Length];
                    reader.ReadValueRaw(array3, 0, array3.Length);
                    return(array3);
                }

                case TypePrefixes.FixArray:
                case TypePrefixes.Array16:
                case TypePrefixes.Array32:
                {
                    object[] array2 = new object[reader.Length];
                    for (int j = 0; j < array2.Length; j++)
                    {
                        array2[j] = Unpack(reader);
                    }
                    return(array2);
                }

                case TypePrefixes.FixMap:
                case TypePrefixes.Map16:
                case TypePrefixes.Map32:
                {
                    IDictionary <object, object> dictionary = new Dictionary <object, object>((int)reader.Length);
                    int length = (int)reader.Length;
                    for (int i = 0; i < length; i++)
                    {
                        object key   = Unpack(reader);
                        object value = Unpack(reader);
                        dictionary.Add(key, value);
                    }
                    return(dictionary);
                }

                case TypePrefixes.Ext8:
                case TypePrefixes.Ext16:
                case TypePrefixes.Ext32:
                {
                    sbyte b = reader.ReadExtType();
                    switch (b)
                    {
                    case 81:
                        if (reader.Length == 16)
                        {
                            float num3 = reader.ReadSingle();
                            float num4 = reader.ReadSingle();
                            float num5 = reader.ReadSingle();
                            float num6 = reader.ReadSingle();
                            return(new Quaternion(num3, num4, num5, num6));
                        }
                        break;

                    case 86:
                        if (reader.Length == 12)
                        {
                            float num7 = reader.ReadSingle();
                            float num8 = reader.ReadSingle();
                            float num9 = reader.ReadSingle();
                            return(new Vector3(num7, num8, num9));
                        }
                        break;

                    case 87:
                        if (reader.Length == 8)
                        {
                            float num  = reader.ReadSingle();
                            float num2 = reader.ReadSingle();
                            return(new Vector2(num, num2));
                        }
                        break;
                    }
                    byte[] array = new byte[reader.Length];
                    reader.ReadValueRaw(array, 0, (int)reader.Length);
                    return(new Ext(b, array));
                }

                default:
                    throw new FormatException();
                }
            }
            throw new FormatException();
        }
Beispiel #3
0
		object Unpack (MsgPackReader reader)
		{
			if (!reader.Read ())
				throw new FormatException ();

			switch (reader.Type) {
				case TypePrefixes.PositiveFixNum:
				case TypePrefixes.NegativeFixNum:
				case TypePrefixes.Int8:
				case TypePrefixes.Int16:
				case TypePrefixes.Int32:
					return reader.ValueSigned;
				case TypePrefixes.Int64:
					return reader.ValueSigned64;
				case TypePrefixes.UInt8:
				case TypePrefixes.UInt16:
				case TypePrefixes.UInt32:
					return reader.ValueUnsigned;
				case TypePrefixes.UInt64:
					return reader.ValueUnsigned64;
				case TypePrefixes.True:
					return true;
				case TypePrefixes.False:
					return false;
				case TypePrefixes.Float:
					return reader.ValueFloat;
				case TypePrefixes.Double:
					return reader.ValueDouble;
				case TypePrefixes.Nil:
					return null;
				case TypePrefixes.FixRaw:
				case TypePrefixes.Raw16:
				case TypePrefixes.Raw32:
					byte[] raw = new byte[reader.Length];
					reader.ReadValueRaw (raw, 0, raw.Length);
					return raw;
				case TypePrefixes.FixArray:
				case TypePrefixes.Array16:
				case TypePrefixes.Array32:
					object[] ary = new object[reader.Length];
					for (int i = 0; i < ary.Length; i ++)
						ary[i] = Unpack (reader);
					return ary;
				case TypePrefixes.FixMap:
				case TypePrefixes.Map16:
				case TypePrefixes.Map32:
					IDictionary<object, object> dic = new Dictionary<object, object> ((int)reader.Length);
					int count = (int)reader.Length;
					for (int i = 0; i < count; i ++) {
						object k = Unpack (reader);
						object v = Unpack (reader);
						dic.Add (k, v);
					}
					return dic;
				default:
					throw new FormatException ();
			}
		}
Beispiel #4
0
        object Unpack(MsgPackReader reader, Type t)
        {
            if (t.IsPrimitive)
            {
                if (!reader.Read())
                {
                    throw new FormatException();
                }
                if (t.Equals(typeof(int)) && reader.IsSigned())
                {
                    return(reader.ValueSigned);
                }
                else if (t.Equals(typeof(uint)) && reader.IsUnsigned())
                {
                    return(reader.ValueUnsigned);
                }
                else if (t.Equals(typeof(float)) && reader.Type == TypePrefixes.Float)
                {
                    return(reader.ValueFloat);
                }
                else if (t.Equals(typeof(double)) && reader.Type == TypePrefixes.Double)
                {
                    return(reader.ValueDouble);
                }
                else if (t.Equals(typeof(long)))
                {
                    if (reader.IsSigned64())
                    {
                        return(reader.ValueSigned64);
                    }
                    if (reader.IsSigned())
                    {
                        return((long)reader.ValueSigned);
                    }
                }
                else if (t.Equals(typeof(ulong)))
                {
                    if (reader.IsUnsigned64())
                    {
                        return(reader.ValueUnsigned64);
                    }
                    if (reader.IsUnsigned())
                    {
                        return((ulong)reader.ValueUnsigned);
                    }
                }
                else if (t.Equals(typeof(bool)) && reader.IsBoolean())
                {
                    return(reader.Type == TypePrefixes.True);
                }
                else if (t.Equals(typeof(byte)) && reader.IsUnsigned())
                {
                    return((byte)reader.ValueUnsigned);
                }
                else if (t.Equals(typeof(sbyte)) && reader.IsSigned())
                {
                    return((sbyte)reader.ValueSigned);
                }
                else if (t.Equals(typeof(short)) && reader.IsSigned())
                {
                    return((short)reader.ValueSigned);
                }
                else if (t.Equals(typeof(ushort)) && reader.IsUnsigned())
                {
                    return((ushort)reader.ValueUnsigned);
                }
                else if (t.Equals(typeof(char)) && reader.IsUnsigned())
                {
                    return((char)reader.ValueUnsigned);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }

            UnpackDelegate unpacker;

            if (UnpackerMapping.TryGetValue(t, out unpacker))
            {
                return(unpacker(this, reader));
            }

            if (t.IsArray)
            {
                if (!reader.Read() || (!reader.IsArray() && reader.Type != TypePrefixes.Nil))
                {
                    throw new FormatException();
                }
                if (reader.Type == TypePrefixes.Nil)
                {
                    return(null);
                }
                Type  et  = t.GetElementType();
                Array ary = Array.CreateInstance(et, (int)reader.Length);
                for (int i = 0; i < ary.Length; i++)
                {
                    ary.SetValue(Unpack(reader, et), i);
                }
                return(ary);
            }

            if (!reader.Read())
            {
                throw new FormatException();
            }
            if (reader.Type == TypePrefixes.Nil)
            {
                return(null);
            }
            if (t.IsInterface)
            {
                if (reader.Type != TypePrefixes.FixArray && reader.Length != 2)
                {
                    throw new FormatException();
                }
                if (!reader.Read() || !reader.IsRaw())
                {
                    throw new FormatException();
                }
                CheckBufferSize((int)reader.Length);
                reader.ReadValueRaw(_buf, 0, (int)reader.Length);
                t = Type.GetType(Encoding.UTF8.GetString(_buf, 0, (int)reader.Length));
                if (!reader.Read() || reader.Type == TypePrefixes.Nil)
                {
                    throw new FormatException();
                }
            }
            if (!reader.IsMap())
            {
                throw new FormatException();
            }

            object o = FormatterServices.GetUninitializedObject(t);
            ReflectionCacheEntry entry = ReflectionCache.Lookup(t);
            int members = (int)reader.Length;

            for (int i = 0; i < members; i++)
            {
                if (!reader.Read() || !reader.IsRaw())
                {
                    throw new FormatException();
                }
                CheckBufferSize((int)reader.Length);
                reader.ReadValueRaw(_buf, 0, (int)reader.Length);
                string    name = Encoding.UTF8.GetString(_buf, 0, (int)reader.Length);
                FieldInfo f;
                if (!entry.FieldMap.TryGetValue(name, out f))
                {
                    throw new FormatException();
                }
                f.SetValue(o, Unpack(reader, f.FieldType));
            }

            IDeserializationCallback callback = o as IDeserializationCallback;

            if (callback != null)
            {
                callback.OnDeserialization(this);
            }
            return(o);
        }
        object Unpack(MsgPackReader reader)
        {
            if (!reader.Read())
            {
                throw new FormatException();
            }

            switch (reader.Type)
            {
            case TypePrefixes.PositiveFixNum:
            case TypePrefixes.NegativeFixNum:
            case TypePrefixes.Int8:
            case TypePrefixes.Int16:
            case TypePrefixes.Int32:
                return(reader.ValueSigned);

            case TypePrefixes.Int64:
                return(reader.ValueSigned64);

            case TypePrefixes.UInt8:
            case TypePrefixes.UInt16:
            case TypePrefixes.UInt32:
                return(reader.ValueUnsigned);

            case TypePrefixes.UInt64:
                return(reader.ValueUnsigned64);

            case TypePrefixes.True:
                return(true);

            case TypePrefixes.False:
                return(false);

            case TypePrefixes.Float:
                return(reader.ValueFloat);

            case TypePrefixes.Double:
                return(reader.ValueDouble);

            case TypePrefixes.Nil:
                return(null);

            case TypePrefixes.FixRaw:
            case TypePrefixes.Raw16:
            case TypePrefixes.Raw32:
                byte[] raw = new byte[reader.Length];
                reader.ReadValueRaw(raw, 0, raw.Length);
                return(raw);

            case TypePrefixes.FixArray:
            case TypePrefixes.Array16:
            case TypePrefixes.Array32:
                object[] ary = new object[reader.Length];
                for (int i = 0; i < ary.Length; i++)
                {
                    ary[i] = Unpack(reader);
                }
                return(ary);

            case TypePrefixes.FixMap:
            case TypePrefixes.Map16:
            case TypePrefixes.Map32:
                IDictionary <object, object> dic = new Dictionary <object, object> ((int)reader.Length);
                int count = (int)reader.Length;
                for (int i = 0; i < count; i++)
                {
                    object k = Unpack(reader);
                    object v = Unpack(reader);
                    dic.Add(k, v);
                }
                return(dic);

            default:
                throw new FormatException();
            }
        }
Beispiel #6
0
        private object Unpack(MsgPackReader reader)
        {
            if (!reader.Read())
            {
                throw new FormatException();
            }
            switch (reader.Type)
            {
            case TypePrefixes.PositiveFixNum:
            case TypePrefixes.Int8:
            case TypePrefixes.Int16:
            case TypePrefixes.Int32:
            case TypePrefixes.NegativeFixNum:
                return(reader.ValueSigned);

            case TypePrefixes.Int64:
                return(reader.ValueSigned64);

            case TypePrefixes.UInt8:
            case TypePrefixes.UInt16:
            case TypePrefixes.UInt32:
                return(reader.ValueUnsigned);

            case TypePrefixes.UInt64:
                return(reader.ValueUnsigned64);

            case TypePrefixes.True:
                return(true);

            case TypePrefixes.False:
                return(false);

            case TypePrefixes.Float:
                return(reader.ValueFloat);

            case TypePrefixes.Double:
                return(reader.ValueDouble);

            case TypePrefixes.Nil:
                return(null);

            case TypePrefixes.FixRaw:
            case TypePrefixes.Raw8:
            case TypePrefixes.Raw16:
            case TypePrefixes.Raw32:
            {
                byte[] array2 = new byte[reader.Length];
                reader.ReadValueRaw(array2, 0, array2.Length);
                return(array2);
            }

            case TypePrefixes.FixArray:
            case TypePrefixes.Array16:
            case TypePrefixes.Array32:
            {
                object[] array = new object[reader.Length];
                for (int j = 0; j < array.Length; j++)
                {
                    array[j] = Unpack(reader);
                }
                return(array);
            }

            case TypePrefixes.FixMap:
            case TypePrefixes.Map16:
            case TypePrefixes.Map32:
            {
                IDictionary <object, object> dictionary = new Dictionary <object, object>((int)reader.Length);
                int length = (int)reader.Length;
                for (int i = 0; i < length; i++)
                {
                    object key   = Unpack(reader) ?? "null";
                    object value = Unpack(reader);

                    if (key is byte[] ba)
                    {
                        key = Encoding.UTF8.GetString(ba);
                    }
                    if (value is byte[] ba2)
                    {
                        value = Encoding.UTF8.GetString(ba2);
                    }

                    dictionary.Add(key, value);
                }
                return(dictionary);
            }

            default:
                throw new FormatException();
            }
        }
Beispiel #7
0
        private object Unpack(MsgPackReader reader, Type t)
        {
            if (t.IsPrimitive)
            {
                if (!reader.Read())
                {
                    throw new FormatException();
                }
                if (t.Equals(typeof(int)) && reader.IsSigned())
                {
                    return(reader.ValueSigned);
                }
                if (t.Equals(typeof(uint)) && reader.IsUnsigned())
                {
                    return(reader.ValueUnsigned);
                }
                if (t.Equals(typeof(float)) && reader.Type == TypePrefixes.Float)
                {
                    return(reader.ValueFloat);
                }
                if (t.Equals(typeof(double)) && reader.Type == TypePrefixes.Double)
                {
                    return(reader.ValueDouble);
                }
                if (t.Equals(typeof(long)))
                {
                    if (reader.IsSigned64())
                    {
                        return(reader.ValueSigned64);
                    }
                    if (reader.IsSigned())
                    {
                        return((long)reader.ValueSigned);
                    }
                }
                else
                {
                    if (!t.Equals(typeof(ulong)))
                    {
                        if (t.Equals(typeof(bool)) && reader.IsBoolean())
                        {
                            return(reader.Type == TypePrefixes.True);
                        }
                        if (t.Equals(typeof(byte)) && reader.IsUnsigned())
                        {
                            return((byte)reader.ValueUnsigned);
                        }
                        if (t.Equals(typeof(sbyte)) && reader.IsSigned())
                        {
                            return((sbyte)reader.ValueSigned);
                        }
                        if (t.Equals(typeof(short)) && reader.IsSigned())
                        {
                            return((short)reader.ValueSigned);
                        }
                        if (t.Equals(typeof(ushort)) && reader.IsUnsigned())
                        {
                            return((ushort)reader.ValueUnsigned);
                        }
                        if (t.Equals(typeof(char)) && reader.IsUnsigned())
                        {
                            return((char)reader.ValueUnsigned);
                        }
                        throw new NotSupportedException();
                    }
                    if (reader.IsUnsigned64())
                    {
                        return(reader.ValueUnsigned64);
                    }
                    if (reader.IsUnsigned())
                    {
                        return((ulong)reader.ValueUnsigned);
                    }
                }
            }
            if (UnpackerMapping.TryGetValue(t, out UnpackDelegate value))
            {
                return(value(this, reader));
            }
            if (t.IsArray)
            {
                if (!reader.Read() || (!reader.IsArray() && reader.Type != TypePrefixes.Nil))
                {
                    throw new FormatException();
                }
                if (reader.Type == TypePrefixes.Nil)
                {
                    return(null);
                }
                Type  elementType = t.GetElementType();
                Array array       = Array.CreateInstance(elementType, (int)reader.Length);
                for (int i = 0; i < array.Length; i++)
                {
                    array.SetValue(Unpack(reader, elementType), i);
                }
                return(array);
            }
            if (!reader.Read())
            {
                throw new FormatException();
            }
            if (reader.Type == TypePrefixes.Nil)
            {
                return(null);
            }
            if (t.IsInterface)
            {
                if (reader.Type != TypePrefixes.FixArray && reader.Length != 2)
                {
                    throw new FormatException();
                }
                if (!reader.Read() || !reader.IsRaw())
                {
                    throw new FormatException();
                }
                CheckBufferSize((int)reader.Length);
                reader.ReadValueRaw(_buf, 0, (int)reader.Length);
                t = Type.GetType(Encoding.UTF8.GetString(_buf, 0, (int)reader.Length));
                if (!reader.Read() || reader.Type == TypePrefixes.Nil)
                {
                    throw new FormatException();
                }
            }
            if (!reader.IsMap())
            {
                throw new FormatException();
            }
            object uninitializedObject = FormatterServices.GetUninitializedObject(t);
            ReflectionCacheEntry reflectionCacheEntry = ReflectionCache.Lookup(t);
            int length = (int)reader.Length;

            for (int j = 0; j < length; j++)
            {
                if (!reader.Read() || !reader.IsRaw())
                {
                    throw new FormatException();
                }
                CheckBufferSize((int)reader.Length);
                reader.ReadValueRaw(_buf, 0, (int)reader.Length);
                string @string = Encoding.UTF8.GetString(_buf, 0, (int)reader.Length);
                if (!reflectionCacheEntry.FieldMap.TryGetValue(@string, out FieldInfo value2))
                {
                    throw new FormatException();
                }
                value2.SetValue(uninitializedObject, Unpack(reader, value2.FieldType));
            }
            (uninitializedObject as IDeserializationCallback)?.OnDeserialization(this);
            return(uninitializedObject);
        }
Beispiel #8
0
        object Unpack(MsgPackReader reader, Type t)
        {
            if (t.IsPrimitive)
            {
                if (!reader.Read())
                {
                    throw new FormatException();
                }
                if (t.Equals(typeof(int)) && reader.IsSigned())
                {
                    return(reader.ValueSigned);
                }
                else if (t.Equals(typeof(uint)) && reader.IsUnsigned())
                {
                    return(reader.ValueUnsigned);
                }
                else if (t.Equals(typeof(float)) && reader.Type == TypePrefixes.Float)
                {
                    return(reader.ValueFloat);
                }
                else if (t.Equals(typeof(double)) && reader.Type == TypePrefixes.Double)
                {
                    return(reader.ValueDouble);
                }
                else if (t.Equals(typeof(long)))
                {
                    if (reader.IsSigned64())
                    {
                        return(reader.ValueSigned64);
                    }
                    if (reader.IsSigned())
                    {
                        return((long)reader.ValueSigned);
                    }
                }
                else if (t.Equals(typeof(ulong)))
                {
                    if (reader.IsUnsigned64())
                    {
                        return(reader.ValueUnsigned64);
                    }
                    if (reader.IsUnsigned())
                    {
                        return((ulong)reader.ValueUnsigned);
                    }
                }
                else if (t.Equals(typeof(bool)) && reader.IsBoolean())
                {
                    return(reader.Type == TypePrefixes.True);
                }
                else if (t.Equals(typeof(byte)) && reader.IsUnsigned())
                {
                    return((byte)reader.ValueUnsigned);
                }
                else if (t.Equals(typeof(sbyte)) && reader.IsSigned())
                {
                    return((sbyte)reader.ValueSigned);
                }
                else if (t.Equals(typeof(short)) && reader.IsSigned())
                {
                    return((short)reader.ValueSigned);
                }
                else if (t.Equals(typeof(ushort)) && reader.IsUnsigned())
                {
                    return((ushort)reader.ValueUnsigned);
                }
                else if (t.Equals(typeof(char)) && reader.IsUnsigned())
                {
                    return((char)reader.ValueUnsigned);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }

            UnpackDelegate unpacker;

            if (UnpackerMapping.TryGetValue(t, out unpacker))
            {
                return(unpacker(this, reader));
            }

            if (typeof(Packable).IsAssignableFrom(t))
            {
                Packable p = Activator.CreateInstance(t) as Packable;
                return(p.Unpack(this, reader));
            }

            if (t.IsArray)
            {
                if (!reader.Read() || (!reader.IsArray() && reader.Type != TypePrefixes.Nil))
                {
                    throw new FormatException();
                }
                if (reader.Type == TypePrefixes.Nil)
                {
                    return(null);
                }
                Type  et  = t.GetElementType();
                Array ary = Array.CreateInstance(et, (int)reader.Length);
                for (int i = 0; i < ary.Length; i++)
                {
                    ary.SetValue(Unpack(reader, et), i);
                }
                return(ary);
            }

            // IEnumerable 型の場合
            // 現在は IList, ISet, IDictionary をサポート
            if (typeof(IEnumerable).IsAssignableFrom(t) && t.IsGenericType)
            {
                Type[] generics = t.GetGenericArguments();

                // IList 型の場合
                if (typeof(IList).IsAssignableFrom(t))
                {
                    if (!reader.Read() || (!reader.IsArray() && reader.Type != TypePrefixes.Nil))
                    {
                        throw new FormatException();
                    }
                    if (reader.Type == TypePrefixes.Nil)
                    {
                        return(null);
                    }

                    Type  et    = generics.Single();
                    int   count = (int)reader.Length;
                    Array ary   = Array.CreateInstance(et, count);

                    for (int i = 0; i < count; i++)
                    {
                        ary.SetValue(Unpack(reader, et), i);
                    }
                    return(Activator.CreateInstance(t, new object[] { ary }));
                }

                // ISet 型の場合
                var setType = typeof(ISet <>).MakeGenericType(generics[0]);
                if (setType.IsAssignableFrom(t))
                {
                    if (!reader.Read() || (!reader.IsArray() && reader.Type != TypePrefixes.Nil))
                    {
                        throw new FormatException();
                    }
                    if (reader.Type == TypePrefixes.Nil)
                    {
                        return(null);
                    }

                    Type et    = generics.Single();
                    int  count = (int)reader.Length;

                    Array ary = Array.CreateInstance(et, count);

                    for (int i = 0; i < count; i++)
                    {
                        ary.SetValue(Unpack(reader, et), i);
                    }
                    return(Activator.CreateInstance(t, new object[] { ary }));
                }

                if (typeof(IDictionary).IsAssignableFrom(t))
                {
                    if (!reader.Read() || (!reader.IsArray() && reader.Type != TypePrefixes.Nil))
                    {
                        throw new FormatException();
                    }
                    if (reader.Type == TypePrefixes.Nil)
                    {
                        return(null);
                    }

                    Type kt = generics[0];
                    Type vt = generics[1];

                    IDictionary dict  = (IDictionary)Activator.CreateInstance(t);
                    int         count = (int)reader.Length;

                    for (int i = 0; i < count; i++)
                    {
                        dict[Unpack(reader, kt)] = Unpack(reader, vt);
                    }
                    return(dict);
                }
            }

            if (!reader.Read())
            {
                throw new FormatException();
            }
            if (reader.Type == TypePrefixes.Nil)
            {
                return(null);
            }
            if (t.IsInterface)
            {
                if (reader.Type != TypePrefixes.FixArray && reader.Length != 2)
                {
                    throw new FormatException();
                }
                if (!reader.Read() || !reader.IsRaw())
                {
                    throw new FormatException();
                }
                CheckBufferSize((int)reader.Length);
                reader.ReadValueRaw(_buf, 0, (int)reader.Length);
                t = Type.GetType(Encoding.UTF8.GetString(_buf, 0, (int)reader.Length));
                if (!reader.Read() || reader.Type == TypePrefixes.Nil)
                {
                    throw new FormatException();
                }
            }
            if (!reader.IsMap())
            {
                throw new FormatException();
            }

            object o = FormatterServices.GetUninitializedObject(t);
            ReflectionCacheEntry entry = ReflectionCache.Lookup(t);
            int members = (int)reader.Length;

            for (int i = 0; i < members; i++)
            {
                if (!reader.Read() || !reader.IsRaw())
                {
                    throw new FormatException();
                }
                CheckBufferSize((int)reader.Length);
                reader.ReadValueRaw(_buf, 0, (int)reader.Length);
                string    name = Encoding.UTF8.GetString(_buf, 0, (int)reader.Length);
                FieldInfo f;

                if (!entry.FieldMap.TryGetValue(name, out f))
                {
                    throw new FormatException();
                }
                f.SetValue(o, Unpack(reader, f.FieldType));
            }

            IDeserializationCallback callback = o as IDeserializationCallback;

            if (callback != null)
            {
                callback.OnDeserialization(this);
            }
            return(o);
        }
        private object Unpack(MsgPackReader reader, Type t)
        {
            //IL_0591: Unknown result type (might be due to invalid IL or missing references)
            //IL_0596: Expected O, but got Unknown
            if (t.IsPrimitive)
            {
                if (!reader.Read())
                {
                    throw new FormatException();
                }
                if (t.Equals(typeof(int)) && reader.IsSigned())
                {
                    return(reader.ValueSigned);
                }
                if (t.Equals(typeof(int)) && reader.IsUnsigned())
                {
                    return((int)reader.ValueUnsigned);
                }
                if (t.Equals(typeof(uint)) && reader.IsUnsigned())
                {
                    return(reader.ValueUnsigned);
                }
                if (t.Equals(typeof(float)))
                {
                    if (reader.Type == TypePrefixes.Float)
                    {
                        return(reader.ValueFloat);
                    }
                    if (reader.Type == TypePrefixes.Double)
                    {
                        return((float)reader.ValueDouble);
                    }
                    if (reader.IsUnsigned())
                    {
                        return((float)(double)reader.ValueUnsigned);
                    }
                    if (reader.IsSigned())
                    {
                        return((float)reader.ValueSigned);
                    }
                }
                else
                {
                    if (t.Equals(typeof(double)) && reader.Type == TypePrefixes.Double)
                    {
                        return(reader.ValueDouble);
                    }
                    if (t.Equals(typeof(long)))
                    {
                        if (reader.IsSigned64())
                        {
                            return(reader.ValueSigned64);
                        }
                        if (reader.IsSigned())
                        {
                            return((long)reader.ValueSigned);
                        }
                        if (reader.IsUnsigned64())
                        {
                            return((long)reader.ValueUnsigned64);
                        }
                        if (reader.IsUnsigned())
                        {
                            return((long)reader.ValueUnsigned);
                        }
                    }
                    else
                    {
                        if (!t.Equals(typeof(ulong)))
                        {
                            if (t.Equals(typeof(bool)) && reader.IsBoolean())
                            {
                                return(reader.Type == TypePrefixes.True);
                            }
                            if (t.Equals(typeof(byte)) && reader.IsUnsigned())
                            {
                                return((byte)reader.ValueUnsigned);
                            }
                            if (t.Equals(typeof(sbyte)) && reader.IsSigned())
                            {
                                return((sbyte)reader.ValueSigned);
                            }
                            if (t.Equals(typeof(short)) && reader.IsSigned())
                            {
                                return((short)reader.ValueSigned);
                            }
                            if (t.Equals(typeof(ushort)) && reader.IsUnsigned())
                            {
                                return((ushort)reader.ValueUnsigned);
                            }
                            if (t.Equals(typeof(char)) && reader.IsUnsigned())
                            {
                                return((char)reader.ValueUnsigned);
                            }
                            throw new NotSupportedException();
                        }
                        if (reader.IsUnsigned64())
                        {
                            return(reader.ValueUnsigned64);
                        }
                        if (reader.IsUnsigned())
                        {
                            return((ulong)reader.ValueUnsigned);
                        }
                    }
                }
            }
            if (UnpackerMapping.TryGetValue(t, out UnpackDelegate value))
            {
                return(value(this, reader));
            }
            if (t.IsArray)
            {
                if (!reader.Read() || (!reader.IsArray() && reader.Type != TypePrefixes.Nil))
                {
                    throw new FormatException();
                }
                if (reader.Type == TypePrefixes.Nil)
                {
                    return(null);
                }
                Type  elementType = t.GetElementType();
                Array array       = Array.CreateInstance(elementType, (int)reader.Length);
                for (int i = 0; i < array.Length; i++)
                {
                    array.SetValue(Unpack(reader, elementType), i);
                }
                return(array);
            }
            if (t.IsEnum)
            {
                if (!reader.Read())
                {
                    throw new FormatException();
                }
                if (reader.IsSigned())
                {
                    return(Enum.ToObject(t, reader.ValueSigned));
                }
                if (reader.IsSigned64())
                {
                    return(Enum.ToObject(t, reader.ValueSigned64));
                }
                if (reader.IsUnsigned())
                {
                    return(Enum.ToObject(t, reader.ValueUnsigned));
                }
                if (reader.IsUnsigned64())
                {
                    return(Enum.ToObject(t, reader.ValueUnsigned64));
                }
                if (reader.IsRaw())
                {
                    CheckBufferSize((int)reader.Length);
                    reader.ReadValueRaw(_buf, 0, (int)reader.Length);
                    string @string = Encoding.UTF8.GetString(_buf, 0, (int)reader.Length);
                    return(Enum.Parse(t, @string));
                }
                throw new FormatException();
            }
            if (!reader.Read())
            {
                throw new FormatException();
            }
            if (reader.Type == TypePrefixes.Nil)
            {
                return(null);
            }
            if (t.IsInterface)
            {
                if (reader.Type != TypePrefixes.FixArray && reader.Length != 2)
                {
                    throw new FormatException();
                }
                if (!reader.Read() || !reader.IsRaw())
                {
                    throw new FormatException();
                }
                CheckBufferSize((int)reader.Length);
                reader.ReadValueRaw(_buf, 0, (int)reader.Length);
                t = Type.GetType(Encoding.UTF8.GetString(_buf, 0, (int)reader.Length));
                if (!reader.Read() || reader.Type == TypePrefixes.Nil)
                {
                    throw new FormatException();
                }
            }
            if (!reader.IsMap())
            {
                throw new FormatException();
            }
            object obj = (!typeof(ScriptableObject).IsAssignableFrom(t)) ? FormatterServices.GetUninitializedObject(t) : ((object)ScriptableObject.CreateInstance(t));
            ReflectionCacheEntry reflectionCacheEntry = ReflectionCache.Lookup(t);
            int length = (int)reader.Length;

            for (int j = 0; j < length; j++)
            {
                if (!reader.Read() || !reader.IsRaw())
                {
                    throw new FormatException();
                }
                CheckBufferSize((int)reader.Length);
                reader.ReadValueRaw(_buf, 0, (int)reader.Length);
                string string2 = Encoding.UTF8.GetString(_buf, 0, (int)reader.Length);
                if (!reflectionCacheEntry.FieldMap.TryGetValue(string2, out FieldInfo value2))
                {
                    new BoxingPacker().Unpack(reader);
                }
                else
                {
                    value2.SetValue(obj, Unpack(reader, value2.FieldType));
                }
            }
            (obj as IDeserializationCallback)?.OnDeserialization(this);
            return(obj);
        }