5 #include <boost/asio.hpp>
16 static void buffer_copy(boost::asio::streambuf & dest,
const boost::asio::streambuf & source)
18 std::size_t bytes_copied =
20 dest.commit(bytes_copied);
23 static boost::asio::streambuf &
30 static PyObject *
view(boost::asio::streambuf &
self)
32 boost::asio::streambuf::const_buffers_type bufs =
self.data();
33 PyObject * py_buffer = PyMemoryView_FromMemory(
34 const_cast<char *
>(
static_cast<const char *
>(bufs.data())),
self.size(), PyBUF_READ);
38 static PyObject *
tobytes(boost::asio::streambuf &
self)
40 return PyBytes_FromObject(
view(
self));
49 typedef boost::asio::streambuf StreamBuffer;
50 if (!eigenpy::register_symbolic_link_to_registered_type<StreamBuffer>())
52 bp::class_<StreamBuffer, boost::noncopyable>(
53 "StreamBuffer",
"Stream buffer to save/load serialized objects in binary mode.",
54 bp::init<>(bp::arg(
"self"),
"Default constructor."))
58 .def(
"max_size", &StreamBuffer::max_size,
"Get the maximum size of the StreamBuffer.")
59 .def(
"prepare",
prepare_proxy,
"Reserve data.", bp::return_self<>())
61 "view",
view,
"Returns the content of *this as a memory view.",
62 bp::with_custodian_and_ward_postcall<0, 1>())
63 .def(
"tobytes",
tobytes,
"Returns the content of *this as a byte sequence.");
67 if (!eigenpy::register_symbolic_link_to_registered_type<StaticBuffer>())
69 bp::class_<StaticBuffer>(
71 "Static buffer to save/load serialized objects in binary mode with pre-allocated memory.",
73 bp::args(
"self",
"size"),
"Default constructor from a given size capacity."))
74 .def(
"size", &
StaticBuffer::size, bp::arg(
"self"),
"Get the size of the input sequence.")
76 "reserve", &StaticBuffer::resize, bp::arg(
"new_size"),
77 "Increase the capacity of the vector to a value that's greater or equal to new_size.");
81 "buffer_copy",
buffer_copy, bp::args(
"dest",
"source"),
82 "Copy bytes from a source buffer to a target buffer.");