41 #include <boost/python.hpp>
44 #include <type_traits>
48 namespace py_bindings_tools
55 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(
ByteString, boost::python::object)
63 :
boost::python::object(
boost::python::handle<>(PyBytes_FromStringAndSize(s.c_str(), s.size())))
68 explicit ByteString(
const boost::python::api::proxy<T>& proxy) :
boost::python::object(proxy)
74 template <typename T, typename std::enable_if<ros::message_traits::IsMessage<T>::value,
int>
::type = 0>
76 :
boost::python::object(
77 boost::python::handle<>(PyBytes_FromStringAndSize(nullptr, ros::serialization::serializationLength(msg))))
79 ros::serialization::OStream stream_arg(
reinterpret_cast<uint8_t*
>(PyBytes_AS_STRING(ptr())),
80 PyBytes_GET_SIZE(ptr()));
81 ros::serialization::serialize(stream_arg, msg);
88 static_assert(
sizeof(uint8_t) ==
sizeof(
char),
"ros/python buffer layout mismatch");
89 char* buf = PyBytes_AsString(ptr());
93 throw std::runtime_error(
"Underlying python object is not a Bytes/String instance");
96 ros::serialization::IStream stream_arg(
reinterpret_cast<uint8_t*
>(buf), PyBytes_GET_SIZE(ptr()));
97 ros::serialization::deserialize(stream_arg, msg);
102 template <
typename T>
109 template <
typename T>
126 struct object_manager_traits<
moveit::py_bindings_tools::ByteString>
127 #if PY_VERSION_HEX >= 0x03000000
128 : pytype_object_manager_traits<&PyBytes_Type, moveit::py_bindings_tools::ByteString>
130 : pytype_object_manager_traits<&PyString_Type, moveit::py_bindings_tools::ByteString>
Main namespace for MoveIt.