bindings/python/serialization/serialization.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2021-2022 INRIA
3 //
4 
5 #include "pinocchio/serialization/archive.hpp"
6 
10 
11 namespace pinocchio
12 {
13  namespace python
14  {
15 
16  static void buffer_copy(boost::asio::streambuf & dest,
17  const boost::asio::streambuf & source)
18  {
19  std::size_t bytes_copied = boost::asio::buffer_copy(dest.prepare(source.size()),source.data());
20  dest.commit(bytes_copied);
21  }
22 
23  static boost::asio::streambuf & prepare_proxy(boost::asio::streambuf & self, const std::size_t n)
24  {
25  self.prepare(n); return self;
26  }
27 
29  {
30  namespace bp = boost::python;
31 
32  bp::scope current_scope = getOrCreatePythonNamespace("serialization");
33 
34  typedef boost::asio::streambuf StreamBuffer;
35  bp::class_<StreamBuffer,boost::noncopyable>("StreamBuffer",
36  "Stream buffer to save/load serialized objects in binary mode.",
37  bp::init<>(bp::arg("self"),"Default constructor."))
38 // .def("capacity",&StreamBuffer::capacity,"Get the current capacity of the StreamBuffer.")
39  .def("size",&StreamBuffer::size,"Get the size of the input sequence.")
40  .def("max_size",&StreamBuffer::max_size,"Get the maximum size of the StreamBuffer.")
41  .def("prepare",prepare_proxy,"Reserve data.",bp::return_internal_reference<>())
42  ;
43 
44  typedef pinocchio::serialization::StaticBuffer StaticBuffer;
45  bp::class_<StaticBuffer>("StaticBuffer",
46  "Static buffer to save/load serialized objects in binary mode with pre-allocated memory.",
47  bp::init<size_t>(bp::args("self","size"),"Default constructor from a given size capacity."))
48  .def("size",&StaticBuffer::size,bp::arg("self"),
49  "Get the size of the input sequence.")
50  .def("reserve",&StaticBuffer::resize,bp::arg("new_size"),
51  "Increase the capacity of the vector to a value that's greater or equal to new_size.")
52  ;
53 
54  bp::def("buffer_copy",buffer_copy,
55  bp::args("dest","source"),
56  "Copy bytes from a source buffer to a target buffer.");
57  }
58 
59  } // namespace python
60 } // namespace pinocchio
Vec3f n
static void buffer_copy(boost::asio::streambuf &dest, const boost::asio::streambuf &source)
Static buffer with pre-allocated memory.
boost::python::object getOrCreatePythonNamespace(const std::string &submodule_name)
Helper to create or simply return an existing namespace in Python.
Definition: namespace.hpp:22
static boost::asio::streambuf & prepare_proxy(boost::asio::streambuf &self, const std::size_t n)
FCL_REAL size() const
Main pinocchio namespace.
Definition: timings.cpp:28


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:32