diff --git a/docs/index.rst b/docs/index.rst index 9072d771..b115941c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -139,11 +139,6 @@ Subscriber .. autoclass:: zenoh.Subscriber :members: -PullSubscriber --------------- -.. autoclass:: zenoh.PullSubscriber - :members: - Reliability ----------- .. autoclass:: zenoh.Reliability diff --git a/examples/z_put.py b/examples/z_put.py index 2f04ab02..07255546 100644 --- a/examples/z_put.py +++ b/examples/z_put.py @@ -17,7 +17,7 @@ import argparse import json import zenoh -from zenoh import config, Value +from zenoh import config # --- Command line argument parsing --- --- --- --- --- --- parser = argparse.ArgumentParser( diff --git a/zenoh/__init__.py b/zenoh/__init__.py index 2cc20137..a66ffcff 100644 --- a/zenoh/__init__.py +++ b/zenoh/__init__.py @@ -14,9 +14,9 @@ from .zenoh import init_logger, scout as _scout from .keyexpr import IntoKeyExpr, IntoSelector, KeyExpr, Selector from .config import Config -from .session import Session, Publisher, Subscriber, PullSubscriber, Info +from .session import Session, Publisher, Subscriber, Info from .enums import CongestionControl, Encoding, Priority, QueryConsolidation, QueryTarget, Reliability, SampleKind -from .value import into_payload, from_payload, Hello, Sample, IntoSample, ZenohId, Timestamp, Reply +from .value import into_payload, from_payload, Hello, Sample, ZenohId, Timestamp, Reply from .closures import Closure, IClosure, IntoClosure, Handler, IHandler, IntoHandler, ListCollector, Queue from .queryable import Queryable, Query from typing import Any diff --git a/zenoh/queryable.py b/zenoh/queryable.py index 93b5b771..a9c14148 100644 --- a/zenoh/queryable.py +++ b/zenoh/queryable.py @@ -15,7 +15,8 @@ from .zenoh import _Query, _Queryable from .keyexpr import KeyExpr, Selector -from .value import Sample, Value, IntoValue, IntoSample +from .value import Sample, Value, IntoPayload, into_payload +from .enums import Encoding class Queryable: """ @@ -80,4 +81,4 @@ def reply_err(self, payload: IntoPayload, encoding: Encoding = None): You may send any amount of replies to a single query, including 0. Sending error responses does not exclude sending other responses. """ - super().reply_err(payload, encoding) + super().reply_err(into_payload(payload), encoding) diff --git a/zenoh/session.py b/zenoh/session.py index 0991629c..8afa75d0 100644 --- a/zenoh/session.py +++ b/zenoh/session.py @@ -19,7 +19,7 @@ from .config import Config from .closures import IntoHandler, Handler, Receiver from .enums import * -from .value import into_payload, IntoValue, Value, Sample, Reply, ZenohId +from .value import into_payload, IntoPayload, Sample, Reply, ZenohId from .queryable import Queryable, Query diff --git a/zenoh/value.py b/zenoh/value.py index 31b44af9..2e5bf91e 100644 --- a/zenoh/value.py +++ b/zenoh/value.py @@ -53,6 +53,43 @@ def from_payload(tp: Type[T], payload: bytes) -> T: return json.loads(payload) raise NotImplementedError() +class Value(_Value): + """ + A Value is a pair of a binary payload, and a mime-type-like encoding string. + + When constructed with ``encoding==None``, the encoding will be selected depending on the payload's type. + """ + def __new__(cls, payload: IntoPayload, encoding: Encoding=None): + return Value.new(into_payload(payload), encoding) + + @staticmethod + def new(payload: bytes, encoding: Encoding = None) -> 'Value': + return Value._upgrade_(_Value.new(payload, encoding)) + + @property + def payload(self) -> bytes: + return super().payload + + @payload.setter + def payload(self, payload: bytes): + super().with_payload(payload) + + @property + def encoding(self) -> Encoding: + return Encoding(super().encoding) + + @encoding.setter + def encoding(self, encoding: Encoding): + super().with_encoding(encoding) + + @staticmethod + def _upgrade_(inner: _Value) -> 'Value': + if inner is None: + return None + if isinstance(inner, Value): + return inner + return _Value.__new__(Value, inner) + class ZenohId(_ZenohId): """A Zenoh UUID""" @staticmethod @@ -115,7 +152,6 @@ def _upgrade_(inner: _QoS) -> 'QoS': QoS.DEFAULT = QoS() -IntoSample = Union[_Sample, Tuple[IntoKeyExpr, IntoValue, SampleKind], Tuple[KeyExpr, IntoValue]] class Sample(_Sample): """ A KeyExpr-Value pair, annotated with the kind (PUT or DELETE) of publication used to emit it and a timestamp.