| 2082 | |
| 2083 | |
| 2084 | class FieldListField(Field[List[Any], List[Any]]): |
| 2085 | __slots__ = ["field", "count_from", "length_from", "max_count"] |
| 2086 | islist = 1 |
| 2087 | |
| 2088 | def __init__( |
| 2089 | self, |
| 2090 | name, # type: str |
| 2091 | default, # type: Optional[List[AnyField]] |
| 2092 | field, # type: AnyField |
| 2093 | length_from=None, # type: Optional[Callable[[Packet], int]] |
| 2094 | count_from=None, # type: Optional[Callable[[Packet], int]] |
| 2095 | max_count=None, # type: Optional[int] |
| 2096 | ): |
| 2097 | # type: (...) -> None |
| 2098 | if default is None: |
| 2099 | default = [] # Create a new list for each instance |
| 2100 | self.field = field |
| 2101 | Field.__init__(self, name, default) |
| 2102 | self.count_from = count_from |
| 2103 | self.length_from = length_from |
| 2104 | self.max_count = max_count |
| 2105 | |
| 2106 | def i2count(self, pkt, val): |
| 2107 | # type: (Optional[Packet], List[Any]) -> int |
| 2108 | if isinstance(val, list): |
| 2109 | return len(val) |
| 2110 | return 1 |
| 2111 | |
| 2112 | def i2len(self, pkt, val): |
| 2113 | # type: (Packet, List[Any]) -> int |
| 2114 | return int(sum(self.field.i2len(pkt, v) for v in val)) |
| 2115 | |
| 2116 | def any2i(self, pkt, x): |
| 2117 | # type: (Optional[Packet], List[Any]) -> List[Any] |
| 2118 | if not isinstance(x, list): |
| 2119 | return [self.field.any2i(pkt, x)] |
| 2120 | else: |
| 2121 | return [self.field.any2i(pkt, e) for e in x] |
| 2122 | |
| 2123 | def i2repr(self, |
| 2124 | pkt, # type: Optional[Packet] |
| 2125 | x, # type: List[Any] |
| 2126 | ): |
| 2127 | # type: (...) -> str |
| 2128 | return "[%s]" % ", ".join(self.field.i2repr(pkt, v) for v in x) |
| 2129 | |
| 2130 | def addfield(self, |
| 2131 | pkt, # type: Packet |
| 2132 | s, # type: bytes |
| 2133 | val, # type: Optional[List[Any]] |
| 2134 | ): |
| 2135 | # type: (...) -> bytes |
| 2136 | val = self.i2m(pkt, val) |
| 2137 | for v in val: |
| 2138 | s = self.field.addfield(pkt, s, v) |
| 2139 | return s |
| 2140 | |
| 2141 | def getfield(self, |
no outgoing calls
no test coverage detected