@@ -431,6 +431,33 @@ impl std::fmt::Debug for Graph {
431431}
432432
433433impl Graph {
434+ /// Create a new Graph using an explicit key expression format.
435+ ///
436+ /// The format determines both the liveliness subscription pattern and the
437+ /// parser used to turn liveliness keys back into ROS entities.
438+ pub fn new (
439+ session : & Session ,
440+ domain_id : usize ,
441+ format : ros_z_protocol:: KeyExprFormat ,
442+ ) -> Result < Self > {
443+ let liveliness_pattern = match format {
444+ ros_z_protocol:: KeyExprFormat :: RmwZenoh => {
445+ format ! ( "{ADMIN_SPACE}/{domain_id}/**" )
446+ }
447+ ros_z_protocol:: KeyExprFormat :: Ros2Dds => "@/*/@ros2_lv/**" . to_string ( ) ,
448+ _ => {
449+ return Err ( zenoh:: Error :: from ( format ! (
450+ "unsupported key expression format for graph construction: {:?}" ,
451+ format
452+ ) ) ) ;
453+ }
454+ } ;
455+
456+ Self :: new_with_pattern ( session, domain_id, liveliness_pattern, move |ke| {
457+ format. parse_liveliness ( ke)
458+ } )
459+ }
460+
434461 async fn wait_until < F > ( & self , timeout : Duration , predicate : F ) -> bool
435462 where
436463 F : Fn ( & Self ) -> bool ,
@@ -458,17 +485,6 @@ impl Graph {
458485 }
459486 }
460487
461- pub fn new ( session : & Session , domain_id : usize ) -> Result < Self > {
462- // Default to RmwZenoh format
463- let format = ros_z_protocol:: KeyExprFormat :: default ( ) ;
464- Self :: new_with_pattern (
465- session,
466- domain_id,
467- format ! ( "{ADMIN_SPACE}/{domain_id}/**" ) ,
468- move |ke| format. parse_liveliness ( ke) ,
469- )
470- }
471-
472488 /// Create a new Graph with a custom liveliness subscription pattern and parser
473489 ///
474490 /// # Arguments
0 commit comments