@@ -54,14 +54,72 @@ use crate::{
5454 net:: primitives:: Primitives ,
5555} ;
5656
57+ pub ( crate ) struct LocalReplyPrimitives {
58+ session : WeakSession ,
59+ }
60+
61+ pub ( crate ) struct RemoteReplyPrimitives {
62+ pub ( crate ) session : Option < WeakSession > ,
63+ pub ( crate ) primitives : Arc < dyn Primitives > ,
64+ }
65+
66+ pub ( crate ) enum ReplyPrimitives {
67+ Local ( LocalReplyPrimitives ) ,
68+ Remote ( RemoteReplyPrimitives ) ,
69+ }
70+
71+ impl ReplyPrimitives {
72+ pub ( crate ) fn new_local ( session : WeakSession ) -> Self {
73+ ReplyPrimitives :: Local ( LocalReplyPrimitives { session } )
74+ }
75+
76+ pub ( crate ) fn new_remote (
77+ session : Option < WeakSession > ,
78+ primitives : Arc < dyn Primitives > ,
79+ ) -> Self {
80+ ReplyPrimitives :: Remote ( RemoteReplyPrimitives {
81+ session,
82+ primitives,
83+ } )
84+ }
85+
86+ pub ( crate ) fn send_response_final ( & self , msg : & mut ResponseFinal ) {
87+ match self {
88+ ReplyPrimitives :: Local ( local) => local. session . send_response_final ( msg) ,
89+ ReplyPrimitives :: Remote ( remote) => remote. primitives . send_response_final ( msg) ,
90+ }
91+ }
92+
93+ pub ( crate ) fn send_response ( & self , msg : & mut Response ) {
94+ match self {
95+ ReplyPrimitives :: Local ( local) => local. session . send_response ( msg) ,
96+ ReplyPrimitives :: Remote ( remote) => remote. primitives . send_response ( msg) ,
97+ }
98+ }
99+
100+ pub ( crate ) fn keyexpr_to_wire ( & self , key_expr : & KeyExpr ) -> WireExpr < ' static > {
101+ match self {
102+ ReplyPrimitives :: Local ( local) => key_expr. to_wire_local ( & local. session ) . to_owned ( ) ,
103+ ReplyPrimitives :: Remote ( remote) => match & remote. session {
104+ Some ( s) => key_expr. to_wire ( & s) . to_owned ( ) ,
105+ None => WireExpr {
106+ scope : 0 ,
107+ suffix : std:: borrow:: Cow :: Owned ( key_expr. as_str ( ) . into ( ) ) ,
108+ mapping : Mapping :: Sender ,
109+ } ,
110+ } ,
111+ }
112+ }
113+ }
114+
57115pub ( crate ) struct QueryInner {
58116 pub ( crate ) key_expr : KeyExpr < ' static > ,
59117 pub ( crate ) parameters : Parameters < ' static > ,
60118 pub ( crate ) qid : RequestId ,
61119 pub ( crate ) zid : ZenohIdProto ,
62120 #[ cfg( feature = "unstable" ) ]
63121 pub ( crate ) source_info : Option < SourceInfo > ,
64- pub ( crate ) primitives : Arc < dyn Primitives > ,
122+ pub ( crate ) primitives : ReplyPrimitives ,
65123}
66124
67125impl QueryInner {
@@ -74,7 +132,7 @@ impl QueryInner {
74132 zid : ZenohIdProto :: default ( ) ,
75133 #[ cfg( feature = "unstable" ) ]
76134 source_info : None ,
77- primitives : Arc :: new ( DummyPrimitives ) ,
135+ primitives : ReplyPrimitives :: new_remote ( None , Arc :: new ( DummyPrimitives ) ) ,
78136 }
79137 }
80138}
@@ -478,11 +536,7 @@ impl Query {
478536 let ext_sinfo = sample. source_info . map ( Into :: into) ;
479537 self . inner . primitives . send_response ( & mut Response {
480538 rid : self . inner . qid ,
481- wire_expr : WireExpr {
482- scope : 0 ,
483- suffix : std:: borrow:: Cow :: Owned ( sample. key_expr . into ( ) ) ,
484- mapping : Mapping :: Sender ,
485- } ,
539+ wire_expr : self . inner . primitives . keyexpr_to_wire ( & sample. key_expr ) ,
486540 payload : ResponseBody :: Reply ( zenoh:: Reply {
487541 consolidation : zenoh:: ConsolidationMode :: DEFAULT ,
488542 ext_unknown : vec ! [ ] ,
0 commit comments