lokinet/pybind/llarp/router_id.cpp

24 lines
743 B
C++
Raw Normal View History

2020-03-01 00:34:48 +00:00
#include "common.hpp"
#include "router_id.hpp"
namespace llarp
{
void
2020-03-07 01:20:11 +00:00
RouterID_Init(py::module& mod)
2020-03-01 00:34:48 +00:00
{
py::class_<RouterID>(mod, "RouterID")
.def(
"FromHex",
[](RouterID* r, const std::string& hex) {
if (hex.size() != 2 * r->size() || !lokimq::is_hex(hex))
throw std::runtime_error("FromHex requires a 64-digit hex string");
lokimq::from_hex(hex.begin(), hex.end(), r->data());
})
2020-03-01 00:34:48 +00:00
.def("__repr__", &RouterID::ToString)
.def("__str__", &RouterID::ToString)
2020-03-01 00:42:42 +00:00
.def("ShortString", &RouterID::ShortString)
.def("__eq__", [](const RouterID& lhs, const RouterID& rhs) { return lhs == rhs; });
2020-03-01 00:34:48 +00:00
}
2020-03-07 01:20:11 +00:00
} // namespace llarp