我想知道如何根据另一个类的字段动态定义一个类的字段类型???我的意思是如何定义一个字段并将其从一个类链接到另一个类,例如:
class TemplateRecord(Packet):
name = "Template Record"
fields_desc = [ ShortField("Type", 0),
ShortField("Length", 0) ]
def extract_padding(self, s):
return "", s
class DataRecord(Packet):
name = "Data Record"
fields_desc = [ ==> Here i would like something like this :
"if Type == 0 from Class TemplateRecord:
IPField("ipsrc", "0.0.0.0"),
if Type == 1 from Class TemplateRecord
IPField("ipdst", "0.0.0.0"),
if Type == 2 from Class TemplateRecord
ByteField("DstMask", 0),
....etc..."
]
def extract_padding(self, s):
return "", s