| 484 | |
| 485 | |
| 486 | class UVarIntField(AbstractUVarIntField): |
| 487 | def __init__(self, name, default, size): |
| 488 | # type: (str, int, int) -> None |
| 489 | """ |
| 490 | :param str name: the name of this field instance. |
| 491 | :param default: the default value for this field instance. default must be positive or null. # noqa: E501 |
| 492 | :raises: AssertionError |
| 493 | """ |
| 494 | assert default >= 0 |
| 495 | assert 0 < size <= 8 |
| 496 | |
| 497 | super(UVarIntField, self).__init__(name, default, size) |
| 498 | self.size = size |
| 499 | self._max_value = (1 << self.size) - 1 |
| 500 | |
| 501 | # Configuring the fake property that is useless for this class but that is # noqa: E501 |
| 502 | # expected from BitFields |
| 503 | self.rev = False |
| 504 | |
| 505 | def h2i(self, pkt, x): |
| 506 | # type: (Optional[packet.Packet], int) -> int |
| 507 | """ h2i is overloaded to restrict the acceptable x values (not None) |
| 508 | |
| 509 | :param packet.Packet|None pkt: the packet instance containing this field instance; probably unused. # noqa: E501 |
| 510 | :param int x: the value to convert. |
| 511 | :return: int: the converted value. |
| 512 | :raises: AssertionError |
| 513 | """ |
| 514 | ret = super(UVarIntField, self).h2i(pkt, x) |
| 515 | assert not isinstance(ret, type(None)) and ret >= 0 |
| 516 | return ret |
| 517 | |
| 518 | def i2h(self, pkt, x): |
| 519 | # type: (Optional[packet.Packet], int) -> int |
| 520 | """ i2h is overloaded to restrict the acceptable x values (not None) |
| 521 | |
| 522 | :param packet.Packet|None pkt: the packet instance containing this field instance; probably unused. # noqa: E501 |
| 523 | :param int x: the value to convert. |
| 524 | :return: int: the converted value. |
| 525 | :raises: AssertionError |
| 526 | """ |
| 527 | ret = super(UVarIntField, self).i2h(pkt, x) |
| 528 | assert not isinstance(ret, type(None)) and ret >= 0 |
| 529 | return ret |
| 530 | |
| 531 | def any2i(self, pkt, x): |
| 532 | # type: (Optional[packet.Packet], Union[str, int]) -> int |
| 533 | """ any2i is overloaded to restrict the acceptable x values (not None) |
| 534 | |
| 535 | :param packet.Packet|None pkt: the packet instance containing this field instance; probably unused. # noqa: E501 |
| 536 | :param str|int x: the value to convert. |
| 537 | :return: int: the converted value. |
| 538 | :raises: AssertionError |
| 539 | """ |
| 540 | ret = super(UVarIntField, self).any2i(pkt, x) |
| 541 | assert not isinstance(ret, type(None)) and ret >= 0 |
| 542 | return ret |
| 543 |
no outgoing calls
no test coverage detected
searching dependent graphs…