@@ -21,13 +21,15 @@ pub struct ZPub<T: ZMessage, S: ZSerializer> {
2121 gid : GidArray ,
2222 inner : zenoh:: pubsub:: Publisher < ' static > ,
2323 _lv_token : LivelinessToken ,
24+ with_attachment : bool ,
2425 _phantom_data : PhantomData < ( T , S ) > ,
2526}
2627
2728#[ derive( Debug ) ]
2829pub struct ZPubBuilder < T , S = CdrSerdes < T > > {
2930 pub entity : EndpointEntity ,
3031 pub session : Arc < Session > ,
32+ pub with_attachment : bool ,
3133 pub _phantom_data : PhantomData < ( T , S ) > ,
3234}
3335
@@ -40,10 +42,16 @@ impl<T, S> ZPubBuilder<T, S> {
4042 self
4143 }
4244
45+ pub fn with_attachment ( mut self , with_attachment : bool ) -> Self {
46+ self . with_attachment = with_attachment;
47+ self
48+ }
49+
4350 pub fn with_serdes < S2 > ( self ) -> ZPubBuilder < T , S2 > {
4451 ZPubBuilder {
4552 entity : self . entity ,
4653 session : self . session ,
54+ with_attachment : self . with_attachment ,
4755 _phantom_data : PhantomData ,
4856 }
4957 }
94102 inner,
95103 _lv_token : lv_token,
96104 gid : self . entity . gid ( ) ,
105+ with_attachment : self . with_attachment ,
97106 _phantom_data : Default :: default ( ) ,
98107 } )
99108 }
@@ -109,22 +118,35 @@ where
109118 }
110119
111120 pub fn publish ( & self , msg : & T ) -> Result < ( ) > {
112- self . inner
113- . put ( S :: serialize ( msg) )
114- . attachment ( self . new_attchment ( ) )
115- . wait ( )
121+ let mut put_builder = self . inner . put ( S :: serialize ( msg) ) ;
122+ if self . with_attachment {
123+ put_builder = put_builder. attachment ( self . new_attchment ( ) ) ;
124+ }
125+ put_builder. wait ( )
116126 }
117127
118128 pub async fn async_publish ( & self , msg : & T ) -> Result < ( ) > {
119- self . inner . put ( S :: serialize ( msg) ) . await
129+ let mut put_builder = self . inner . put ( S :: serialize ( msg) ) ;
130+ if self . with_attachment {
131+ put_builder = put_builder. attachment ( self . new_attchment ( ) ) ;
132+ }
133+ put_builder. await
120134 }
121135
122136 pub fn publish_serialized_message ( & self , msg : & [ u8 ] ) -> Result < ( ) > {
123- self . inner . put ( msg) . wait ( )
137+ let mut put_builder = self . inner . put ( msg) ;
138+ if self . with_attachment {
139+ put_builder = put_builder. attachment ( self . new_attchment ( ) ) ;
140+ }
141+ put_builder. wait ( )
124142 }
125143
126144 pub fn publish_sample ( & self , msg : & Sample ) -> Result < ( ) > {
127- self . inner . put ( msg. payload ( ) . to_bytes ( ) ) . wait ( )
145+ let mut put_builder = self . inner . put ( msg. payload ( ) . to_bytes ( ) ) ;
146+ if self . with_attachment {
147+ put_builder = put_builder. attachment ( self . new_attchment ( ) ) ;
148+ }
149+ put_builder. wait ( )
128150 }
129151}
130152
0 commit comments