| 1590 | |
| 1591 | |
| 1592 | class PacketLenField(_PacketFieldSingle[Optional[BasePacket]]): |
| 1593 | __slots__ = ["length_from"] |
| 1594 | |
| 1595 | def __init__(self, |
| 1596 | name, # type: str |
| 1597 | default, # type: Packet |
| 1598 | cls, # type: Union[Callable[[bytes], Packet], Type[Packet]] # noqa: E501 |
| 1599 | length_from=None # type: Optional[Callable[[Packet], int]] # noqa: E501 |
| 1600 | ): |
| 1601 | # type: (...) -> None |
| 1602 | super(PacketLenField, self).__init__(name, default, cls) |
| 1603 | self.length_from = length_from or (lambda x: 0) |
| 1604 | |
| 1605 | def getfield(self, |
| 1606 | pkt, # type: Packet |
| 1607 | s, # type: bytes |
| 1608 | ): |
| 1609 | # type: (...) -> Tuple[bytes, Optional[BasePacket]] |
| 1610 | len_pkt = self.length_from(pkt) |
| 1611 | i = None |
| 1612 | if len_pkt: |
| 1613 | try: |
| 1614 | i = self.m2i(pkt, s[:len_pkt]) |
| 1615 | except Exception: |
| 1616 | if conf.debug_dissector: |
| 1617 | raise |
| 1618 | i = conf.raw_layer(load=s[:len_pkt]) |
| 1619 | return s[len_pkt:], i |
| 1620 | |
| 1621 | |
| 1622 | class PacketListField(_PacketField[List[BasePacket]]): |
no outgoing calls
no test coverage detected