| 1 |  |  | // | 
    
    | 2 |  |  | // Copyright (c) 2021-2022 INRIA | 
    
    | 3 |  |  | // | 
    
    | 4 |  |  |  | 
    
    | 5 |  |  | #include "pinocchio/serialization/archive.hpp" | 
    
    | 6 |  |  |  | 
    
    | 7 |  |  | #include "pinocchio/bindings/python/fwd.hpp" | 
    
    | 8 |  |  | #include "pinocchio/bindings/python/utils/namespace.hpp" | 
    
    | 9 |  |  | #include "pinocchio/bindings/python/serialization/serialization.hpp" | 
    
    | 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 |  |  |  | 
    
    | 28 |  | 19 |     void exposeSerialization() | 
    
    | 29 |  |  |     { | 
    
    | 30 |  |  |       namespace bp = boost::python; | 
    
    | 31 |  |  |  | 
    
    | 32 | ✓✗✓✗ ✓✗
 | 38 |       bp::scope current_scope = getOrCreatePythonNamespace("serialization"); | 
    
    | 33 |  |  |  | 
    
    | 34 |  |  |       typedef boost::asio::streambuf StreamBuffer; | 
    
    | 35 | ✓✗ | 19 |       bp::class_<StreamBuffer,boost::noncopyable>("StreamBuffer", | 
    
    | 36 |  |  |                                                   "Stream buffer to save/load serialized objects in binary mode.", | 
    
    | 37 | ✓✗✓✗ 
 | 38 |                                                   bp::init<>(bp::arg("self"),"Default constructor.")) | 
    
    | 38 |  |  | //      .def("capacity",&StreamBuffer::capacity,"Get the current capacity of the StreamBuffer.") | 
    
    | 39 | ✓✗ | 19 |       .def("size",&StreamBuffer::size,"Get the size of the input sequence.") | 
    
    | 40 | ✓✗ | 19 |       .def("max_size",&StreamBuffer::max_size,"Get the maximum size of the StreamBuffer.") | 
    
    | 41 | ✓✗ | 19 |       .def("prepare",prepare_proxy,"Reserve data.",bp::return_internal_reference<>()) | 
    
    | 42 |  |  |       ; | 
    
    | 43 |  |  |  | 
    
    | 44 |  |  |       typedef pinocchio::serialization::StaticBuffer StaticBuffer; | 
    
    | 45 | ✓✗ | 19 |       bp::class_<StaticBuffer>("StaticBuffer", | 
    
    | 46 |  |  |                                "Static buffer to save/load serialized objects in binary mode with pre-allocated memory.", | 
    
    | 47 | ✓✗✓✗ 
 | 38 |                                bp::init<size_t>(bp::args("self","size"),"Default constructor from a given size capacity.")) | 
    
    | 48 | ✓✗ | 38 |       .def("size",&StaticBuffer::size,bp::arg("self"), | 
    
    | 49 | ✓✗ | 19 |            "Get the size of the input sequence.") | 
    
    | 50 | ✓✗ | 38 |       .def("reserve",&StaticBuffer::resize,bp::arg("new_size"), | 
    
    | 51 | ✓✗ | 19 |            "Increase the capacity of the vector to a value that's greater or equal to new_size.") | 
    
    | 52 |  |  |       ; | 
    
    | 53 |  |  |  | 
    
    | 54 | ✓✗ | 19 |       bp::def("buffer_copy",buffer_copy, | 
    
    | 55 | ✓✗ | 38 |               bp::args("dest","source"), | 
    
    | 56 |  |  |               "Copy bytes from a source buffer to a target buffer."); | 
    
    | 57 |  | 19 |     } | 
    
    | 58 |  |  |  | 
    
    | 59 |  |  |   } // namespace python | 
    
    | 60 |  |  | } // namespace pinocchio |