@@ -2427,7 +2427,7 @@ class BitField(_BitField[int]):
24272427 __doc__ = _BitField .__doc__
24282428
24292429
2430- class BitFixedLenField (BitField ):
2430+ class BitLenField (BitField ):
24312431 __slots__ = ["length_from" ]
24322432
24332433 def __init__ (self ,
@@ -2437,15 +2437,15 @@ def __init__(self,
24372437 ):
24382438 # type: (...) -> None
24392439 self .length_from = length_from
2440- super (BitFixedLenField , self ).__init__ (name , default , 0 )
2440+ super (BitLenField , self ).__init__ (name , default , 0 )
24412441
24422442 def getfield (self , # type: ignore
24432443 pkt , # type: Packet
24442444 s , # type: Union[Tuple[bytes, int], bytes]
24452445 ):
24462446 # type: (...) -> Union[Tuple[Tuple[bytes, int], int], Tuple[bytes, int]] # noqa: E501
24472447 self .size = self .length_from (pkt )
2448- return super (BitFixedLenField , self ).getfield (pkt , s )
2448+ return super (BitLenField , self ).getfield (pkt , s )
24492449
24502450 def addfield (self , # type: ignore
24512451 pkt , # type: Packet
@@ -2454,7 +2454,7 @@ def addfield(self, # type: ignore
24542454 ):
24552455 # type: (...) -> Union[Tuple[bytes, int, int], bytes]
24562456 self .size = self .length_from (pkt )
2457- return super (BitFixedLenField , self ).addfield (pkt , s , val )
2457+ return super (BitLenField , self ).addfield (pkt , s , val )
24582458
24592459
24602460class BitFieldLenField (BitField ):
@@ -2661,6 +2661,32 @@ def i2repr(self,
26612661 return _EnumField .i2repr (self , pkt , x )
26622662
26632663
2664+ class BitLenEnumField (BitLenField , _EnumField [int ]):
2665+ __slots__ = EnumField .__slots__
2666+
2667+ def __init__ (self ,
2668+ name , # type: str
2669+ default , # type: Optional[int]
2670+ length_from , # type: Callable[[Packet], int]
2671+ enum , # type: Dict[int, str]
2672+ ** kwargs , # type: Any
2673+ ):
2674+ # type: (...) -> None
2675+ _EnumField .__init__ (self , name , default , enum )
2676+ BitLenField .__init__ (self , name , default , length_from , ** kwargs )
2677+
2678+ def any2i (self , pkt , x ):
2679+ # type: (Optional[Packet], Any) -> int
2680+ return _EnumField .any2i (self , pkt , x ) # type: ignore
2681+
2682+ def i2repr (self ,
2683+ pkt , # type: Optional[Packet]
2684+ x , # type: Union[List[int], int]
2685+ ):
2686+ # type: (...) -> Any
2687+ return _EnumField .i2repr (self , pkt , x )
2688+
2689+
26642690class ShortEnumField (EnumField [int ]):
26652691 __slots__ = EnumField .__slots__
26662692
0 commit comments