When you have weird/complex fields, you typically want to implement your own Field
class in Scapy. This is rather easy to do, you just have to define a getfield
function for dissection and addfield
for build.
Here's an example that is somewhat relevant: https://github.com/secdev/scapy/blob/bff1ea03f5258f713ec900fd7bdaa546c7b566aa/scapy/contrib/mqttsn.py#L93
The longer documentation would be located over https://scapy.readthedocs.io/en/latest/build_dissect.html#fields