void serialize()

in src/pythonserialization.h [283:317]


void serialize(X& x, const py::handle& v) {
  if (!v) {
    throw SerializationError("Attempt to serialize a null python handle");
  }
  if (v.ptr() == Py_True) {
    x(pyTypes::bool_, true);
  } else if (v.ptr() == Py_False) {
    x(pyTypes::bool_, false);
  } else if (v.ptr() == Py_None) {
    x(pyTypes::none);
  } else if (py::isinstance<py::float_>(v)) {
    x(pyTypes::float_, (float)py::reinterpret_borrow<py::float_>(v));
  } else if (py::isinstance<py::dict>(v)) {
    x(pyTypes::dict, py::reinterpret_borrow<py::dict>(v));
  } else if (py::isinstance<py::str>(v)) {
    x(pyTypes::str, py::reinterpret_borrow<py::str>(v));
  } else if (py::isinstance<py::array>(v)) {
    x(pyTypes::array, py::reinterpret_borrow<py::array>(v));
  } else if (py::isinstance<py::int_>(v)) {
    x(pyTypes::int_, (int64_t)py::reinterpret_borrow<py::int_>(v));
  } else if (py::isinstance<py::list>(v)) {
    x(pyTypes::list, py::reinterpret_borrow<py::list>(v));
  } else if (auto t = tryFromPython(v.ptr()); t) {
    x(pyTypes::tensor, *t);
  } else if (py::isinstance<py::tuple>(v)) {
    x(pyTypes::tuple, py::reinterpret_borrow<py::tuple>(v));
  } else if (py::isinstance<py::args>(v)) {
    x(pyTypes::args, py::reinterpret_borrow<py::args>(v));
  } else if (py::isinstance<py::kwargs>(v)) {
    x(pyTypes::kwargs, py::reinterpret_borrow<py::kwargs>(v));
  } else {
    x(pyTypes::pickled);
    picklex(x, v);
  }
}