salilab / rmf

The library to support reading and writing of RMF files.
https://integrativemodeling.org/rmf/
Apache License 2.0
8 stars 0 forks source link

Add python pickle support for RMF::BufferConstHandle #113

Closed drussel closed 10 years ago

benmwebb commented 10 years ago

One way to do this is to override the __setstate__ and __getstate__ methods, which handle the dict that gets pickled. e.g.

def __getstate__(self):
    d = self.__dict__.copy()
    del d['swig_pointer']  # Can't pickle the underlying C++ object
    d['__serialize'] = self.get_byte_string()
    return d
def __setstate__(self, d):
    b = d.pop('__serialize')
    self.__dict__.update(d)
    self.set_byte_string(b)