Same as FieldLenField but takes a tuple of fields for length_of.
| 98 | |
| 99 | |
| 100 | class _FieldsLenField(Field[int, int]): |
| 101 | """Same as FieldLenField but takes a tuple of fields for length_of.""" |
| 102 | |
| 103 | __slots__ = ["length_of", "adjust"] |
| 104 | |
| 105 | def __init__( |
| 106 | self, |
| 107 | name, # type: str |
| 108 | default, # type: Optional[Any] |
| 109 | length_of=None, # type: Optional[Tuple[str]] |
| 110 | fmt="H", # type: str |
| 111 | adjust=lambda pkt, x: x, # type: Callable[[Packet, int], int] |
| 112 | ): |
| 113 | # type: (...) -> None |
| 114 | super(_FieldsLenField, self).__init__(name, default, fmt) |
| 115 | self.length_of = length_of |
| 116 | self.adjust = adjust |
| 117 | |
| 118 | def i2m(self, pkt, x): |
| 119 | # type: (Optional[Packet], Optional[int]) -> int |
| 120 | if x is None and pkt is not None: |
| 121 | if self.length_of is not None: |
| 122 | f = 0 |
| 123 | for length_of_field in self.length_of: |
| 124 | fld, fval = pkt.getfield_and_val(length_of_field) |
| 125 | f += fld.i2len(pkt, fval) |
| 126 | else: |
| 127 | raise ValueError("Field should have either length_of or count_of") |
| 128 | x = self.adjust(pkt, f) |
| 129 | elif x is None: |
| 130 | x = 0 |
| 131 | return x |
| 132 | |
| 133 | |
| 134 | def determine_pg_field(pkt, lst, cur, remain): |
no outgoing calls
no test coverage detected
searching dependent graphs…