USRP Hardware Driver and USRP Manual  Version: 4.4.0.HEAD-0-g5fac246b
UHD and USRP Manual
pybind_adaptors.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2020 Ettus Research, a National Instruments Brand
3 //
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 //
6 
7 #pragma once
8 
9 #include <pybind11/pybind11.h>
10 #include <pybind11/stl.h>
11 
12 namespace pybind11 { namespace detail {
13 template <typename T>
14 struct type_caster<boost::optional<T>> : optional_caster<boost::optional<T>>
15 {
16 };
17 }} // namespace pybind11::detail
18 
19 std::vector<uint8_t> pybytes_to_vector(const py::bytes& data)
20 {
21  const std::string data_str = std::string(data);
22  return std::vector<uint8_t>(data_str.cbegin(), data_str.cend());
23 }
24 
25 py::bytes vector_to_pybytes(const std::vector<uint8_t>& data)
26 {
27  return py::bytes(std::string(data.cbegin(), data.cend()));
28 }
29 
30 std::vector<uint64_t> pybytes_to_u64_vector(const py::bytes& data)
31 {
32  const std::string data_str = std::string(data);
33  return std::vector<uint64_t>(data_str.cbegin(), data_str.cend());
34 }
35 
36 py::bytes u64_vector_to_pybytes(const std::vector<uint64_t>& data)
37 {
38  return py::bytes(std::string(data.cbegin(), data.cend()));
39 }
u64_vector_to_pybytes
py::bytes u64_vector_to_pybytes(const std::vector< uint64_t > &data)
Definition: pybind_adaptors.hpp:36
vector_to_pybytes
py::bytes vector_to_pybytes(const std::vector< uint8_t > &data)
Definition: pybind_adaptors.hpp:25
pybytes_to_u64_vector
std::vector< uint64_t > pybytes_to_u64_vector(const py::bytes &data)
Definition: pybind_adaptors.hpp:30
pybytes_to_vector
std::vector< uint8_t > pybytes_to_vector(const py::bytes &data)
Definition: pybind_adaptors.hpp:19
pybind11
Definition: pybind_adaptors.hpp:12