Takes a dictionary as an argument and packs back into a byte string.
| 65 | |
| 66 | |
| 67 | class _DictStrField(StrField): |
| 68 | """Takes a dictionary as an argument and packs back into a byte string.""" |
| 69 | |
| 70 | def i2m(self, pkt, x): |
| 71 | if isinstance(x, bytes): |
| 72 | return x |
| 73 | if isinstance(x, dict): |
| 74 | result = bytes() |
| 75 | for k, v in x.items(): |
| 76 | result += k + b"\x00" + v + b"\x00" |
| 77 | return result + b"\x00" |
| 78 | else: |
| 79 | return super(_DictStrField, self).i2m(pkt, x) |
| 80 | |
| 81 | def i2len(self, pkt, x): |
| 82 | # type: (Optional[Packet], Any) -> int |
| 83 | if x is None: |
| 84 | return 0 |
| 85 | return len(self.i2m(pkt, x)) |
| 86 | |
| 87 | |
| 88 | class Startup(Packet): |
no outgoing calls
no test coverage detected
searching dependent graphs…