@@ -84,6 +84,7 @@ def _rebuild_pkt(
8484 fields , # type: Dict[str, Any]
8585 payload , # type: Optional[Packet]
8686 metadata , # type: Dict[str, Any]
87+ extra_slots = None , # type: Dict[str, Any]
8788):
8889 # type: (...) -> Packet
8990 """Helper for unpickling Packet instances via field values."""
@@ -98,6 +99,9 @@ def _rebuild_pkt(
9899 pkt .sniffed_on = metadata ['sniffed_on' ]
99100 pkt .wirelen = metadata ['wirelen' ]
100101 pkt .comments = metadata ['comments' ]
102+ # Restore any extra __slots__ defined by subclasses
103+ for attr , value in extra_slots .items ():
104+ setattr (pkt , attr , value )
101105 return pkt
102106
103107
@@ -279,9 +283,14 @@ def __reduce__(self):
279283 'wirelen' : self .wirelen ,
280284 'comments' : self .comments ,
281285 }
286+ # Collect any extra __slots__ defined by subclasses
287+ extra_slots = {}
288+ for attr in type (self ).__all_slots__ - set (Packet .__slots__ ):
289+ if hasattr (self , attr ):
290+ extra_slots [attr ] = getattr (self , attr )
282291 return (
283292 _rebuild_pkt ,
284- (self .__class__ , fields , payload , metadata ),
293+ (self .__class__ , fields , payload , metadata , extra_slots ),
285294 )
286295
287296 def __deepcopy__ (self ,
0 commit comments