示例#1
0
        /// <summary>
        /// Unpack and override target from packet
        /// </summary>
        /// <typeparam name="T">unpackable type</typeparam>
        /// <param name="target">unpackable target</param>
        public static void Unpack <T>(ref T target, GSFPacket packet)
        {
            Type          type   = typeof(T);
            PacketUtility packer = GetUtil(type);

            packer.unpack(ref target, packet);
        }
示例#2
0
        /// <summary>
        /// Unpack and override target from packet
        /// </summary>
        /// <typeparam name="T">unpackable type</typeparam>
        public static T Unpack <T>(GSFPacket packet)
        {
            Type          type   = typeof(T);
            PacketUtility packer = GetUtil(type);

            return(packer.unpack <T>(packet));
        }
        public override object unpack(GSFPacket packet)
        {
            object[] data = (object[])packet.data;
            Type     type = UnpackType((TypeInfo)data[0]);

            GSFPacket[] values = (GSFPacket[])data[1];
            // get utility of element type
            PacketUtility util      = GetUtil(type.GetElementType());
            object        array     = Activator.CreateInstance(type, new object[] { values.Length });
            MethodInfo    setMethod = type.GetMethod("Set");

            for (int i = 0; i < values.Length; i++)
            {
                setMethod.Invoke(array, new object[] { i, util.unpack(values[i]) });
            }
            return(array);
        }
        public override object unpack(GSFPacket packet, Type type)
        {
            object[]      data    = (object[])packet.data;
            Type          keyType = type.GetGenericArguments()[0];
            Type          valType = type.GetGenericArguments()[1];
            PacketUtility keyUtil = GetUtil(keyType);
            PacketUtility valUtil = GetUtil(valType);
            object        dict    = Activator.CreateInstance(type);

            object[]   values    = (object[])data[1];
            MethodInfo addMethod = type.GetMethod("Add");

            for (int i = 0; i < values.Length; i += 2)
            {
                addMethod.Invoke(dict, new object[] { keyUtil.unpack((GSFPacket)values[i]), valUtil.unpack((GSFPacket)values[i + 1]) });
            }
            return(dict);
        }
        public override void unpack(ref object target, GSFPacket packet)
        {
            object[]      data     = (object[])packet.data;
            Type          dictType = target.GetType();
            Type          keyType  = dictType.GetGenericArguments()[0];
            Type          valType  = dictType.GetGenericArguments()[1];
            PacketUtility keyUtil  = GetUtil(keyType);
            PacketUtility valUtil  = GetUtil(valType);

            object[]   values      = (object[])data[1];
            MethodInfo clearMethod = dictType.GetMethod("Clear");

            clearMethod.Invoke(target, new object[0]);
            MethodInfo addMethod = dictType.GetMethod("Add");

            for (int i = 0; i < values.Length; i += 2)
            {
                addMethod.Invoke(target, new object[] { keyUtil.unpack((GSFPacket)values[i], keyType), valUtil.unpack((GSFPacket)values[i + 1], valType) });
            }
        }
示例#6
0
        public virtual object unpack(GSFPacket packet, Type type)
        {
            PacketUtility util = GetUtil(type);

            return(util.unpack(packet));
        }
 public override object unpack(GSFPacket packet)
 {
     return(proxy.unpack(packet));
 }
        public override object Unpack(GSFPacket packet)
        {
            PacketUtility util = GetUtil(packet.classID);

            return(util.unpack(packet));
        }