@@ -141,29 +141,33 @@ impl<T, S> ZPubBuilder<T, S> {
141141 pub fn with_dyn_schema ( mut self , schema : Arc < crate :: dynamic:: schema:: MessageSchema > ) -> Self {
142142 use crate :: dynamic:: MessageSchemaTypeDescription ;
143143
144- // Compute TypeInfo from schema for proper key expression matching with ROS 2
145- // Convert ROS 2 canonical name to DDS name
146- // "std_msgs/msg/String" → "std_msgs::msg::dds_::String_"
147- let dds_name = schema. type_name
148- . replace ( "/msg/" , "::msg::dds_::" )
149- . replace ( "/srv/" , "::srv::dds_::" )
150- . replace ( "/action/" , "::action::dds_::" )
151- + "_" ;
152-
153- // Convert schema TypeHash to entity TypeHash via RIHS string
154- let type_hash = match schema. compute_type_hash ( ) {
155- Ok ( hash) => {
156- let rihs_string = hash. to_rihs_string ( ) ;
157- crate :: entity:: TypeHash :: from_rihs_string ( & rihs_string)
158- . unwrap_or_else ( crate :: entity:: TypeHash :: zero)
159- }
160- Err ( _) => crate :: entity:: TypeHash :: zero ( ) ,
161- } ;
144+ // Only compute and set type_info if it hasn't been set already
145+ // (e.g., from create_dyn_sub_auto which provides the publisher's hash)
146+ if self . entity . type_info . is_none ( ) {
147+ // Compute TypeInfo from schema for proper key expression matching with ROS 2
148+ // Convert ROS 2 canonical name to DDS name
149+ // "std_msgs/msg/String" → "std_msgs::msg::dds_::String_"
150+ let dds_name = schema. type_name
151+ . replace ( "/msg/" , "::msg::dds_::" )
152+ . replace ( "/srv/" , "::srv::dds_::" )
153+ . replace ( "/action/" , "::action::dds_::" )
154+ + "_" ;
155+
156+ // Convert schema TypeHash to entity TypeHash via RIHS string
157+ let type_hash = match schema. compute_type_hash ( ) {
158+ Ok ( hash) => {
159+ let rihs_string = hash. to_rihs_string ( ) ;
160+ crate :: entity:: TypeHash :: from_rihs_string ( & rihs_string)
161+ . unwrap_or_else ( crate :: entity:: TypeHash :: zero)
162+ }
163+ Err ( _) => crate :: entity:: TypeHash :: zero ( ) ,
164+ } ;
162165
163- self . entity . type_info = Some ( crate :: entity:: TypeInfo {
164- name : dds_name,
165- hash : type_hash,
166- } ) ;
166+ self . entity . type_info = Some ( crate :: entity:: TypeInfo {
167+ name : dds_name,
168+ hash : type_hash,
169+ } ) ;
170+ }
167171
168172 self . dyn_schema = Some ( schema) ;
169173 self
@@ -449,29 +453,33 @@ where
449453 pub fn with_dyn_schema ( mut self , schema : Arc < crate :: dynamic:: schema:: MessageSchema > ) -> Self {
450454 use crate :: dynamic:: MessageSchemaTypeDescription ;
451455
452- // Compute TypeInfo from schema for proper key expression matching with ROS 2
453- // Convert ROS 2 canonical name to DDS name
454- // "std_msgs/msg/String" → "std_msgs::msg::dds_::String_"
455- let dds_name = schema. type_name
456- . replace ( "/msg/" , "::msg::dds_::" )
457- . replace ( "/srv/" , "::srv::dds_::" )
458- . replace ( "/action/" , "::action::dds_::" )
459- + "_" ;
460-
461- // Convert schema TypeHash to entity TypeHash via RIHS string
462- let type_hash = match schema. compute_type_hash ( ) {
463- Ok ( hash) => {
464- let rihs_string = hash. to_rihs_string ( ) ;
465- crate :: entity:: TypeHash :: from_rihs_string ( & rihs_string)
466- . unwrap_or_else ( crate :: entity:: TypeHash :: zero)
467- }
468- Err ( _) => crate :: entity:: TypeHash :: zero ( ) ,
469- } ;
456+ // Only compute and set type_info if it hasn't been set already
457+ // (e.g., from create_dyn_sub_auto which provides the publisher's hash)
458+ if self . entity . type_info . is_none ( ) {
459+ // Compute TypeInfo from schema for proper key expression matching with ROS 2
460+ // Convert ROS 2 canonical name to DDS name
461+ // "std_msgs/msg/String" → "std_msgs::msg::dds_::String_"
462+ let dds_name = schema. type_name
463+ . replace ( "/msg/" , "::msg::dds_::" )
464+ . replace ( "/srv/" , "::srv::dds_::" )
465+ . replace ( "/action/" , "::action::dds_::" )
466+ + "_" ;
467+
468+ // Convert schema TypeHash to entity TypeHash via RIHS string
469+ let type_hash = match schema. compute_type_hash ( ) {
470+ Ok ( hash) => {
471+ let rihs_string = hash. to_rihs_string ( ) ;
472+ crate :: entity:: TypeHash :: from_rihs_string ( & rihs_string)
473+ . unwrap_or_else ( crate :: entity:: TypeHash :: zero)
474+ }
475+ Err ( _) => crate :: entity:: TypeHash :: zero ( ) ,
476+ } ;
470477
471- self . entity . type_info = Some ( crate :: entity:: TypeInfo {
472- name : dds_name,
473- hash : type_hash,
474- } ) ;
478+ self . entity . type_info = Some ( crate :: entity:: TypeInfo {
479+ name : dds_name,
480+ hash : type_hash,
481+ } ) ;
482+ }
475483
476484 self . dyn_schema = Some ( schema) ;
477485 self
0 commit comments