Making a deep copy of an OPF model

I think you can probably use the new or old serialization completely in memory. The old method requires separate steps for the Python state (pickle) and C++ state so the new method is probably easier (and faster).

For the new method, you can see how to do an in-memory copy here:

It might be faster to use to_bytes_packed and from_bytes_packed instead of the unpacked version used in the example code. See pycapnp reference here:
http://jparyani.github.io/pycapnp/capnp.html#capnp._DynamicStructBuilder.to_bytes_packed
http://jparyani.github.io/pycapnp/capnp.html#capnp._StructModule.from_bytes_packed

1 Like