|
|
@@ -33,3 +33,29 @@ PyObject *Extension<Datagram>::
|
|
|
__bytes__() const {
|
|
|
return get_message();
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * This special Python method is implemented to provide support for the pickle
|
|
|
+ * module.
|
|
|
+ */
|
|
|
+INLINE PyObject *Extension<Datagram>::
|
|
|
+__reduce__() const {
|
|
|
+ // We should return at least a 2-tuple, (Class, (args)): the necessary class
|
|
|
+ // object whose constructor we should call (e.g. this), and the arguments
|
|
|
+ // necessary to reconstruct this object.
|
|
|
+ PyObject *args;
|
|
|
+ if (_this->get_length() > 0) {
|
|
|
+ args = PyTuple_New(1);
|
|
|
+ PyTuple_SET_ITEM(args, 0, get_message());
|
|
|
+ } else {
|
|
|
+ args = PyTuple_New(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ extern struct Dtool_PyTypedObject Dtool_Datagram;
|
|
|
+ Py_INCREF((PyObject *)&Dtool_Datagram._PyType);
|
|
|
+
|
|
|
+ PyObject *result = PyTuple_New(2);
|
|
|
+ PyTuple_SET_ITEM(result, 0, (PyObject *)&Dtool_Datagram._PyType);
|
|
|
+ PyTuple_SET_ITEM(result, 1, args);
|
|
|
+ return result;
|
|
|
+}
|