Skip to content

Commit

Permalink
Implement __getstate__ and __setstate__ on Container
Browse files Browse the repository at this point in the history
  • Loading branch information
kohlrabi committed Oct 24, 2023
1 parent 7a85d81 commit 363db84
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions construct/lib/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ def search_all(self, pattern):
compiled_pattern = re.compile(pattern)
return self._search(compiled_pattern, True)

def __getstate__(self):
"""
Used by pickle to serialize an instance to a dict.
"""
ret = OrderedDict(self)
return ret

def __setstate__(self, state):
"""
Used by pickle to de-serialize from a dict.
"""
self.clear()
self.update(state)


class ListContainer(list):
r"""
Expand Down

0 comments on commit 363db84

Please sign in to comment.