def packet2dict(packet, timestamp, *, data_link):
def wrapper(packet):<EOL><INDENT>dict_ = dict()<EOL>for field in packet.__hdr_fields__:<EOL><INDENT>dict_[field] = getattr(packet, field, None)<EOL><DEDENT>payload = packet.data<EOL>if not isinstance(payload, bytes):<EOL><INDENT>dict_[type(payload).__name__] = wrapper(payload)<EOL><DEDENT>return dict_<EOL><DEDENT>return {<EOL>'<STR_LIT>': timestamp,<EOL>'<STR_LIT>': packet.pack(),<EOL>data_link.name: wrapper(packet),<EOL>}<EOL>
Convert DPKT packet into dict.