Python Class, String, Dictionary?

I am parsing a TCP / IP packet into a string format. What is the best way to structure and store? Should I store it as a ctypes structure, a python class, a dictionary, or some other way? What are the advantages and disadvantages of each method?

+3
source share
3 answers

You must use a class. This gives you maximum flexibility in the future.

Dictionaries have more detailed syntax for accessing their contents and do not allow adding methods if you need them.

ctypes is really designed to access structures packaged for use in other APIs. If your data will remain in Python, the only advantage is that it will be more compact in memory.

+8

,

  • , thisPacket ['srcPort']
  • MongoDB (, , 80, - )
+1

I am a big fan of detailed requirements.

Without this, I would go with a named tuple.

You can do things like thisPacket.srcPort.

Then you can just drag and drop your packages into something like MongoDB and request them cool later.

+1
source

Source: https://habr.com/ru/post/1791393/


All Articles