diff --git a/python/opendht.pyx b/python/opendht.pyx index bc2f619e..574596f2 100644 --- a/python/opendht.pyx +++ b/python/opendht.pyx @@ -30,6 +30,7 @@ from libcpp.map cimport map as map from libcpp cimport bool from libcpp.utility cimport pair +from libcpp.string cimport string from cython.parallel import parallel, prange from cython.operator cimport dereference as deref, preincrement as inc, predecrement as dec @@ -117,6 +118,11 @@ cdef class Value(object): self._value.reset(new cpp.Value(val, len(val))) def __str__(self): return self._value.get().toString().decode() + property data: + def __get__(self): + string(self._value.get().data.data(), self._value.get().data.size()) + def __set__(self, bytes value): + self._value.get().data = value cdef class NodeSetIter(object): cdef map[cpp.InfoHash, cpp.shared_ptr[cpp.Node]]* _nodes diff --git a/python/opendht_cpp.pxd b/python/opendht_cpp.pxd index fe0236cf..c7ac337a 100644 --- a/python/opendht_cpp.pxd +++ b/python/opendht_cpp.pxd @@ -45,6 +45,7 @@ cdef extern from "opendht/value.h" namespace "dht": Value(vector[uint8_t]) except + Value(const uint8_t* dat_ptr, size_t dat_len) except + string toString() const + vector[uint8_t] data cdef extern from "opendht/crypto.h" namespace "dht::crypto": ctypedef pair[shared_ptr[PrivateKey], shared_ptr[Certificate]] Identity