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); } }
public void AddField(int Index, EPacketFieldType Type, object Value) { ISerializableField Field = PacketProcessor.GetFieldType(Type); if (Field != null) { Field.Index = Index; Field.val = Value; Field.PacketType = Type; AddField(Index, Field); } }
public void ConvertToField() { FieldInfo[] Fields = GetType().GetFields(); foreach (FieldInfo Info in Fields) { 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(this); Field.PacketType = PacketProcessor.GetFieldType(Field); AddField(Field.Index, Field); } } }
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); } }
public override void Deserialize(ref PacketInStream Data) { long ListData = Data.ReadEncoded7Bit(); int ListType; int ListCount; PacketInStream.Decode2Parameters(ListData, out ListType, out ListCount); List <ISerializableField> Fields = new List <ISerializableField>(); Log.Debug("Packet", "------> List : " + ListType + "(" + ListCount + ")"); for (int i = 0; i < ListCount; ++i) { ISerializableField Field = PacketProcessor.GetFieldType((EPacketFieldType)ListType); if (Field != null) { Field.Deserialize(ref Data); Fields.Add(Field); } } val = Fields; }