How GoPickle's unpickling machine works
masterGoPickle implements a virtual unpickling machine (PM) that executes a sequence of opcodes to reconstruct Python objects.
Core Components
- Opcodes: The machine processes a sequence of instructions (similar to Python's
pickletools) to build complex objects. - Types: The library uses a
typessub-package containing Go representations of Python classes, instances, and common builtin non-scalar types. - Extensibility: Because Python can serialize any object, GoPickle uses a
GenericClassfor unknown types. If a pickle requires specific traits thatGenericClasscannot provide, users must implement a custom class via theFindClasscallback. - Interface-based design: Once objects are resolved, they are cast to
interface{}. The machine only checks for specific interfaces when strictly necessary to maintain performance and simplicity.