Skip to content

Commit 5823285

Browse files
Merge branch 'main' into advanced-pubsub
2 parents b3b1642 + 567f82d commit 5823285

5 files changed

Lines changed: 74 additions & 35 deletions

File tree

Cargo.lock

Lines changed: 30 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import tomllib
2727

2828
import zenoh
29+
import zenoh.ext
2930

3031
# -- Project information -----------------------------------------------------
3132

docs/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,10 @@ module zenoh.handlers
7474
.. automodule:: zenoh.handlers
7575
:members:
7676
:undoc-members:
77+
78+
module zenoh.ext
79+
================
80+
81+
.. automodule:: zenoh.ext
82+
:members:
83+
:undoc-members:

src/bytes.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ impl ZBytes {
4949
}
5050
}
5151

52-
fn to_bytes(&self) -> Cow<[u8]> {
53-
self.0.to_bytes()
52+
fn to_bytes<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyBytes>> {
53+
// Not using `ZBytes::to_bytes`
54+
PyBytes::new_bound_with(py, self.0.len(), |bytes| {
55+
self.0.reader().read_exact(bytes).into_pyres()
56+
})
5457
}
5558

5659
fn to_string(&self) -> PyResult<Cow<str>> {
@@ -68,9 +71,11 @@ impl ZBytes {
6871
}
6972

7073
fn __bytes__<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyBytes>> {
71-
PyBytes::new_bound_with(py, self.0.len(), |bytes| {
72-
self.0.reader().read_exact(bytes).into_pyres()
73-
})
74+
self.to_bytes(py)
75+
}
76+
77+
fn __str__(&self) -> PyResult<Cow<str>> {
78+
self.to_string()
7479
}
7580

7681
fn __eq__(&self, other: &Bound<PyAny>) -> PyResult<bool> {

zenoh/ext.pyi

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,32 @@ class Float64(float):
7171
class ZDeserializeError(Exception):
7272
pass
7373

74-
def z_serialize(obj: Any) -> ZBytes: ...
75-
def z_deserialize(tp: type[_T], zbytes: ZBytes) -> _T: ...
74+
def z_serialize(obj: Any) -> ZBytes:
75+
"""Serialize an object of supported type according to the `Zenoh serialization format <https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Serialization.md>`_.
76+
77+
Supported types are:
78+
79+
* UInt8, UInt16, Uint32, UInt64, UInt128, Int8, Int16, Int32, Int64, Int128, int (handled as int32), Float32, Float64, float (handled as Float64), bool;
80+
81+
* Str, Bytes, ByteArray;
82+
83+
* List, Dict, Set, FrozenSet and Tuple of supported types.
84+
"""
85+
pass
86+
87+
def z_deserialize(tp: type[_T], zbytes: ZBytes) -> _T:
88+
"""Deserialize into an object of supported type according to the `Zenoh serialization format <https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Serialization.md>`_.
89+
90+
Supported types are:
91+
92+
* UInt8, UInt16, Uint32, UInt64, UInt128, Int8, Int16, Int32, Int64, Int128, int (handled as int32), Float32, Float64, float (handled as Float64), bool;
93+
94+
* Str, Bytes, ByteArray;
95+
96+
* List, Dict, Set, FrozenSet and Tuple of supported types.
97+
"""
98+
pass
99+
76100
@_unstable
77101
@final
78102
class AdvancedPublisher:

0 commit comments

Comments
 (0)