@@ -181,6 +181,7 @@ def __init__(self,
181181 # Clarify the meaning for this `explicit` flag.
182182 # Now that cache is cleared as soon as the packet is modified, possibly we could get rid of it?
183183 self .explicit = 0
184+ #: Caches bytes after `dissect()` or `build()` for the current layer only (not the payload, even if set).
184185 self .raw_packet_cache = None # type: Optional[bytes]
185186 self .wirelen = None # type: Optional[int]
186187 self .direction = None # type: Optional[int]
@@ -379,12 +380,12 @@ def get_field(self, fld):
379380 """DEV: returns the field instance from the name of the field"""
380381 return self .fieldtype [fld ]
381382
382- def add_payload (self , payload , clear_cache = True ):
383- # type: (Union[Packet, bytes], bool ) -> None
383+ def add_payload (self , payload ):
384+ # type: (Union[Packet, bytes]) -> None
384385 if payload is None :
385386 return
386387 elif not isinstance (self .payload , NoPayload ):
387- self .payload .add_payload (payload , clear_cache = clear_cache )
388+ self .payload .add_payload (payload )
388389 else :
389390 if isinstance (payload , Packet ):
390391 self .payload = payload
@@ -398,19 +399,12 @@ def add_payload(self, payload, clear_cache=True):
398399 else :
399400 raise TypeError ("payload must be 'Packet', 'bytes', 'str', 'bytearray', or 'memoryview', not [%s]" % repr (payload )) # noqa: E501
400401
401- # Invalidate cache when the packet has changed.
402- if clear_cache :
403- self .clear_cache (upwards = True , downwards = False )
404-
405402 def remove_payload (self ):
406403 # type: () -> None
407404 self .payload .remove_underlayer (self )
408405 self .payload = NoPayload ()
409406 self .overloaded_fields = {}
410407
411- # Invalidate cache when the packet has changed.
412- self .clear_cache (upwards = True , downwards = False )
413-
414408 def add_underlayer (self , underlayer ):
415409 # type: (Packet) -> None
416410 self .underlayer = underlayer
@@ -1203,7 +1197,7 @@ def do_dissect_payload(self, s):
12031197 ):
12041198 # stop dissection here
12051199 p = conf .raw_layer (s , _internal = 1 , _underlayer = self )
1206- self .add_payload (p , clear_cache = False )
1200+ self .add_payload (p )
12071201 return
12081202 cls = self .guess_payload_class (s )
12091203 try :
@@ -1226,7 +1220,7 @@ def do_dissect_payload(self, s):
12261220 if cls is not None :
12271221 raise
12281222 p = conf .raw_layer (s , _internal = 1 , _underlayer = self )
1229- self .add_payload (p , clear_cache = False )
1223+ self .add_payload (p )
12301224
12311225 def dissect (self , s ):
12321226 # type: (bytes) -> None
0 commit comments