示例#1
0
        private uint GetPacketId(ISerializablePacket packet)
        {
            var typeInfo = packet.GetType().GetTypeInfo();
            var attr     = typeInfo.GetCustomAttribute <PacketAttribute>();

            return(attr.PacketId);
        }
示例#2
0
        public static byte[] FieldToBytes(ISerializablePacket Packet, string FieldName)
        {
            FieldInfo Info = Packet.GetType().GetField(FieldName);
            ISerializableFieldAttribute[] FieldsAttr = Info.GetCustomAttributes(typeof(ISerializableFieldAttribute), true) as ISerializableFieldAttribute[];
            if (FieldsAttr != null && FieldsAttr.Length > 0)
            {
                ISerializableField Field = Activator.CreateInstance(FieldsAttr[0].GetSerializableType()) as ISerializableField;
                Field.Index = FieldsAttr[0].Index;
                Field.val = Info.GetValue(Packet);
                Field.PacketType = PacketProcessor.GetFieldType(Field);

                PacketOutStream Str = new PacketOutStream();
                Field.Serialize(ref Str,true);
                byte[] Result =  Str.ToArray();
                return Result;
            }
            else
                return null;
        }
示例#3
0
        public static void BytesToField(ISerializablePacket Packet, byte[] Bytes, string FieldName)
        {
            if (Bytes == null || Bytes.Length <= 0)
                return;

            FieldInfo Info = Packet.GetType().GetField(FieldName);
            ISerializableFieldAttribute[] FieldsAttr = Info.GetCustomAttributes(typeof(ISerializableFieldAttribute), true) as ISerializableFieldAttribute[];
            if (FieldsAttr != null && FieldsAttr.Length > 0)
            {
                ISerializableField Field = Activator.CreateInstance(FieldsAttr[0].GetSerializableType()) as ISerializableField;
                Field.Index = FieldsAttr[0].Index;
                Field.val = Info.GetValue(Packet);
                Field.PacketType = PacketProcessor.GetFieldType(Field);

                PacketInStream Str = new PacketInStream(Bytes, Bytes.Length);
                Field.Deserialize(ref Str);
                Field.ApplyToFieldInfo(Info, Packet, Info.FieldType);
            }
            else
                Info.SetValue(Packet, null);
        }