Struct zenoh::net::Session [−][src]
pub struct Session { /* fields omitted */ }
Expand description
A zenoh-net session.
Implementations
pub fn declare_resource(
&self,
resource: &ResKey
) -> impl ZFuture<Output = ZResult<ResourceId>>
pub fn declare_resource(
&self,
resource: &ResKey
) -> impl ZFuture<Output = ZResult<ResourceId>>
Associate a numerical Id with the given resource key.
This numerical Id will be used on the network to save bandwidth and ease the retrieval of the concerned resource in the routing tables.
Arguments
resource
- The resource key to map to a numerical Id
Examples
use zenoh::net::*;
let session = open(config::peer()).await.unwrap();
let rid = session.declare_resource(&"/resource/name".into()).await.unwrap();
Undeclare the numerical Id/resource key association previously declared with declare_resource.
Arguments
rid
- The numerical Id to unmap
Examples
use zenoh::net::*;
let session = open(config::peer()).await.unwrap();
let rid = session.declare_resource(&"/resource/name".into()).await.unwrap();
session.undeclare_resource(rid).await;
Declare a Publisher for the given resource key.
Written resources that match the given key will only be sent on the network if matching subscribers exist in the system.
Arguments
resource
- The resource key to publish
Examples
use zenoh::net::*;
let session = open(config::peer()).await.unwrap();
let publisher = session.declare_publisher(&"/resource/name".into()).await.unwrap();
session.write(&"/resource/name".into(), "value".as_bytes().into()).await.unwrap();
pub fn declare_subscriber(
&self,
reskey: &ResKey,
info: &SubInfo
) -> impl ZFuture<Output = ZResult<Subscriber<'_>>>
pub fn declare_subscriber(
&self,
reskey: &ResKey,
info: &SubInfo
) -> impl ZFuture<Output = ZResult<Subscriber<'_>>>
Declare a Subscriber for the given resource key.
Arguments
resource
- The resource key to subscribeinfo
- The SubInfo to configure the subscription
Examples
use zenoh::net::*;
use futures::prelude::*;
let session = open(config::peer()).await.unwrap();
let sub_info = SubInfo {
reliability: Reliability::Reliable,
mode: SubMode::Push,
period: None
};
let mut subscriber = session.declare_subscriber(&"/resource/name".into(), &sub_info).await.unwrap();
while let Some(sample) = subscriber.receiver().next().await {
println!("Received : {:?}", sample);
}
Declare a CallbackSubscriber for the given resource key.
Arguments
resource
- The resource key to subscribeinfo
- The SubInfo to configure the subscriptiondata_handler
- The callback that will be called on each data reception
Examples
use zenoh::net::*;
let session = open(config::peer()).await.unwrap();
let sub_info = SubInfo {
reliability: Reliability::Reliable,
mode: SubMode::Push,
period: None
};
let subscriber = session.declare_callback_subscriber(&"/resource/name".into(), &sub_info,
|sample| { println!("Received : {} {}", sample.res_name, sample.payload); }
).await.unwrap();
pub fn declare_local_subscriber(
&self,
reskey: &ResKey
) -> impl ZFuture<Output = ZResult<Subscriber<'_>>>
pub fn declare_local_subscriber(
&self,
reskey: &ResKey
) -> impl ZFuture<Output = ZResult<Subscriber<'_>>>
This is an experimental API.
Declare a Queryable for the given resource key.
Arguments
Examples
use zenoh::net::*;
use zenoh::net::queryable::EVAL;
use futures::prelude::*;
let session = open(config::peer()).await.unwrap();
let mut queryable = session.declare_queryable(&"/resource/name".into(), EVAL).await.unwrap();
while let Some(query) = queryable.receiver().next().await {
query.reply_async(Sample{
res_name: "/resource/name".to_string(),
payload: "value".as_bytes().into(),
data_info: None,
}).await;
}
Write data with options.
Arguments
resource
- The resource key to writepayload
- The value to writeencoding
- The encoding of the valuekind
- The kind of valuecongestion_control
- The value for the congestion control
Examples
use zenoh::net::*;
let session = open(config::peer()).await.unwrap();
session.write_ext(&"/resource/name".into(), "value".as_bytes().into(), encoding::TEXT_PLAIN, data_kind::PUT, CongestionControl::Drop).await.unwrap();
pub fn query(
&self,
resource: &ResKey,
predicate: &str,
target: QueryTarget,
consolidation: QueryConsolidation
) -> impl ZFuture<Output = ZResult<ReplyReceiver>>
pub fn query(
&self,
resource: &ResKey,
predicate: &str,
target: QueryTarget,
consolidation: QueryConsolidation
) -> impl ZFuture<Output = ZResult<ReplyReceiver>>
Query data from the matching queryables in the system.
Arguments
resource
- The resource key to querypredicate
- An indication to matching queryables about the queried datatarget
- The kind of queryables that should be target of this queryconsolidation
- The kind of consolidation that should be applied on replies
Examples
use zenoh::net::*;
use futures::prelude::*;
let session = open(config::peer()).await.unwrap();
let mut replies = session.query(
&"/resource/name".into(),
"predicate",
QueryTarget::default(),
QueryConsolidation::default()
).await.unwrap();
while let Some(reply) = replies.next().await {
println!(">> Received {:?}", reply.data);
}
Trait Implementations
fn decl_subscriber(
&self,
_reskey: &ResKey,
_sub_info: &SubInfo,
_routing_context: Option<RoutingContext>
)
fn decl_queryable(
&self,
_reskey: &ResKey,
_kind: ZInt,
_routing_context: Option<RoutingContext>
)
fn send_data(
&self,
reskey: &ResKey,
payload: ZBuf,
channel: Channel,
congestion_control: CongestionControl,
info: Option<DataInfo>,
_routing_context: Option<RoutingContext>
)
fn send_query(
&self,
reskey: &ResKey,
predicate: &str,
qid: ZInt,
target: QueryTarget,
consolidation: QueryConsolidation,
_routing_context: Option<RoutingContext>
)
fn send_reply_data(
&self,
qid: ZInt,
replier_kind: ZInt,
replier_id: PeerId,
reskey: ResKey,
data_info: Option<DataInfo>,
payload: ZBuf
)
Auto Trait Implementations
impl !RefUnwindSafe for Session
impl !UnwindSafe for Session
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more