From 1bc00ee2f19c37f6d08c4947a648c5b5f1675e14 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 19 Dec 2021 11:08:49 +0000 Subject: [PATCH] remove stuttering in names --- src/dds/dp_event_loop.rs | 4 +- src/dds/message_receiver.rs | 7 +-- src/dds/mod.rs | 8 +-- src/dds/participant.rs | 4 +- src/dds/pubsub.rs | 2 +- src/dds/qos.rs | 2 + src/dds/reader.rs | 20 +++---- src/dds/with_key/datareader.rs | 10 ++-- src/dds/writer.rs | 14 ++--- .../data_types/spdp_participant_data.rs | 4 +- src/discovery/discovery.rs | 17 +++--- src/discovery/discovery_db.rs | 14 ++--- src/lib.rs | 1 - src/messages/submessages/info_destination.rs | 2 +- src/messages/submessages/info_source.rs | 2 +- src/ros2/builtin_datatypes.rs | 2 +- src/structure/entity.rs | 2 +- src/structure/guid.rs | 60 +++++++++---------- src/test/test_data.rs | 4 +- 19 files changed, 86 insertions(+), 93 deletions(-) diff --git a/src/dds/dp_event_loop.rs b/src/dds/dp_event_loop.rs index f8b6d615..16fec820 100644 --- a/src/dds/dp_event_loop.rs +++ b/src/dds/dp_event_loop.rs @@ -497,7 +497,7 @@ impl DPEventLoop { fn handle_writer_acknack_action(&mut self, _event: &Event) { while let Ok((acknack_sender_prefix, acknack_submessage)) = self.ack_nack_receiver.try_recv() { let writer_guid = GUID::new_with_prefix_and_id( - self.domain_info.domain_participant_guid.guid_prefix, + self.domain_info.domain_participant_guid.prefix, acknack_submessage.writer_id(), ); if let Some(found_writer) = self.writers.get_mut(&writer_guid.entity_id) { @@ -518,7 +518,7 @@ impl DPEventLoop { info!( "update_participant {:?} myself={}", participant_guid_prefix, - participant_guid_prefix == self.domain_info.domain_participant_guid.guid_prefix + participant_guid_prefix == self.domain_info.domain_participant_guid.prefix ); { diff --git a/src/dds/message_receiver.rs b/src/dds/message_receiver.rs index 2b9a4bfb..961afd99 100644 --- a/src/dds/message_receiver.rs +++ b/src/dds/message_receiver.rs @@ -371,7 +371,7 @@ impl MessageReceiver { } } InterpreterSubmessage::InfoDestination(info_dest, _flags) => { - if info_dest.guid_prefix == GUID::GUID_UNKNOWN.guid_prefix { + if info_dest.guid_prefix == GUID::GUID_UNKNOWN.prefix { self.dest_guid_prefix = self.own_guid_prefix; } else { self.dest_guid_prefix = info_dest.guid_prefix; @@ -483,7 +483,6 @@ mod tests { EntityId::create_custom_entity_id([0, 0, 0], EntityKind::READER_WITH_KEY_USER_DEFINED); let new_guid = GUID::new_with_prefix_and_id(gui_prefix, entity); - new_guid.from_prefix(entity); let (send, _rec) = mio_channel::sync_channel::<()>(100); let (status_sender, _status_receiver) = mio_extras::channel::sync_channel::(100); @@ -604,7 +603,7 @@ mod tests { mio_channel::sync_channel::<(GuidPrefix, AckSubmessage)>(10); let (spdp_liveness_sender, _spdp_liveness_receiver) = mio_channel::sync_channel(8); let mut message_receiver = - MessageReceiver::new(guid_new.guid_prefix, acknack_sender, spdp_liveness_sender); + MessageReceiver::new(guid_new.prefix, acknack_sender, spdp_liveness_sender); message_receiver.handle_received_packet(&udp_bits1); assert_eq!(message_receiver.submessage_count, 4); @@ -616,7 +615,7 @@ mod tests { #[test] fn mr_test_header() { let guid_new = GUID::default(); - let header = Header::new(guid_new.guid_prefix); + let header = Header::new(guid_new.prefix); let bytes = header.write_to_vec().unwrap(); let new_header = Header::read_from_buffer(&bytes).unwrap(); diff --git a/src/dds/mod.rs b/src/dds/mod.rs index 4e7047e5..88538311 100644 --- a/src/dds/mod.rs +++ b/src/dds/mod.rs @@ -59,12 +59,12 @@ pub mod data_types { } // DDS Error and Result types -pub use crate::dds::values::result::*; - pub use participant::DomainParticipant; pub use topic::{Topic, TopicKind}; pub use pubsub::{Publisher, Subscriber}; +pub use crate::dds::values::result::*; // Discovery results -pub use crate::discovery::data_types::topic_data::{DiscoveredTopicData, SubscriptionBuiltinTopicData}; - +pub use crate::discovery::data_types::topic_data::{ + DiscoveredTopicData, SubscriptionBuiltinTopicData, +}; diff --git a/src/dds/participant.rs b/src/dds/participant.rs index c8647bf3..978e798b 100644 --- a/src/dds/participant.rs +++ b/src/dds/participant.rs @@ -735,7 +735,7 @@ impl DomainParticipantInner { listeners, dds_cache_clone, disc_db_clone, - new_guid.guid_prefix, + new_guid.prefix, TokenReceiverPair { token: ADD_READER_TOKEN, receiver: receiver_add_reader, @@ -1120,7 +1120,7 @@ mod tests { protocol_id: ProtocolId::default(), protocol_version: ProtocolVersion { major: 2, minor: 3 }, vendor_id: VendorId::THIS_IMPLEMENTATION, - guid_prefix: GUID::default().guid_prefix, + guid_prefix: GUID::default().prefix, }; m.set_header(h); m.add_submessage(s); diff --git a/src/dds/pubsub.rs b/src/dds/pubsub.rs index 384788a3..268b0911 100644 --- a/src/dds/pubsub.rs +++ b/src/dds/pubsub.rs @@ -471,7 +471,7 @@ impl InnerPublisher { .ok_or("upgrade fail") .or_else(|e| log_and_err_internal!("Where is my DomainParticipant? {}", e))?; - let guid = GUID::new_with_prefix_and_id(dp.guid().guid_prefix, entity_id); + let guid = GUID::new_with_prefix_and_id(dp.guid().prefix, entity_id); let new_writer = WriterIngredients { guid, diff --git a/src/dds/qos.rs b/src/dds/qos.rs index f7217f02..757dd853 100644 --- a/src/dds/qos.rs +++ b/src/dds/qos.rs @@ -54,6 +54,7 @@ pub enum QosPolicyId { /// Utility for building [QosPolicies] #[derive(Default)] +#[must_use] pub struct QosPolicyBuilder { durability: Option, presentation: Option, @@ -243,6 +244,7 @@ impl QosPolicies { /// /// Constructs a QosPolicy, where each policy is taken from `self`, /// and overwritten with those policies from `other` that are defined. + #[must_use] pub fn modify_by(&self, other: &QosPolicies) -> QosPolicies { QosPolicies { durability: other.durability.or(self.durability), diff --git a/src/dds/reader.rs b/src/dds/reader.rs index ac52c102..40c2388e 100644 --- a/src/dds/reader.rs +++ b/src/dds/reader.rs @@ -917,7 +917,7 @@ impl Reader { protocol_id: ProtocolId::default(), protocol_version: ProtocolVersion::THIS_IMPLEMENTATION, vendor_id: VendorId::THIS_IMPLEMENTATION, - guid_prefix: self.my_guid.guid_prefix, + guid_prefix: self.my_guid.prefix, }); match info_dst.create_submessage(infodst_flags) { @@ -952,7 +952,7 @@ impl Reader { count: self.sent_ack_nack_count, }, InfoDestination { - guid_prefix: writer_proxy.remote_writer_guid.guid_prefix, + guid_prefix: writer_proxy.remote_writer_guid.prefix, }, &writer_proxy.unicast_locator_list, ); @@ -1052,14 +1052,14 @@ mod tests { ); let writer_guid = GUID { - guid_prefix: GuidPrefix::new(&[1; 12]), + prefix: GuidPrefix::new(&[1; 12]), entity_id: EntityId::create_custom_entity_id( [1; 3], EntityKind::WRITER_WITH_KEY_USER_DEFINED, ), }; let mr_state = MessageReceiverState { - source_guid_prefix: writer_guid.guid_prefix, + source_guid_prefix: writer_guid.prefix, ..Default::default() }; @@ -1118,7 +1118,7 @@ mod tests { ); let writer_guid = GUID { - guid_prefix: GuidPrefix::new(&[1; 12]), + prefix: GuidPrefix::new(&[1; 12]), entity_id: EntityId::create_custom_entity_id( [1; 3], EntityKind::WRITER_WITH_KEY_USER_DEFINED, @@ -1126,7 +1126,7 @@ mod tests { }; let mr_state = MessageReceiverState { - source_guid_prefix: writer_guid.guid_prefix, + source_guid_prefix: writer_guid.prefix, ..Default::default() }; @@ -1193,7 +1193,7 @@ mod tests { ); let writer_guid = GUID { - guid_prefix: GuidPrefix::new(&[1; 12]), + prefix: GuidPrefix::new(&[1; 12]), entity_id: EntityId::create_custom_entity_id( [1; 3], EntityKind::WRITER_WITH_KEY_USER_DEFINED, @@ -1203,7 +1203,7 @@ mod tests { let writer_id = writer_guid.entity_id; let mr_state = MessageReceiverState { - source_guid_prefix: writer_guid.guid_prefix, + source_guid_prefix: writer_guid.prefix, ..Default::default() }; @@ -1327,7 +1327,7 @@ mod tests { ); let writer_guid = GUID { - guid_prefix: GuidPrefix::new(&[1; 12]), + prefix: GuidPrefix::new(&[1; 12]), entity_id: EntityId::create_custom_entity_id( [1; 3], EntityKind::WRITER_WITH_KEY_USER_DEFINED, @@ -1336,7 +1336,7 @@ mod tests { let writer_id = writer_guid.entity_id; let mr_state = MessageReceiverState { - source_guid_prefix: writer_guid.guid_prefix, + source_guid_prefix: writer_guid.prefix, ..Default::default() }; diff --git a/src/dds/with_key/datareader.rs b/src/dds/with_key/datareader.rs index 02c11b69..e719a7cb 100644 --- a/src/dds/with_key/datareader.rs +++ b/src/dds/with_key/datareader.rs @@ -1341,14 +1341,14 @@ mod tests { let data_key = random_data.key(); let writer_guid = GUID { - guid_prefix: GuidPrefix::new(&[1; 12]), + prefix: GuidPrefix::new(&[1; 12]), entity_id: EntityId::create_custom_entity_id( [1; 3], EntityKind::WRITER_WITH_KEY_USER_DEFINED, ), }; let mr_state = MessageReceiverState { - source_guid_prefix: writer_guid.guid_prefix, + source_guid_prefix: writer_guid.prefix, ..Default::default() }; @@ -1475,14 +1475,14 @@ mod tests { .unwrap(); let writer_guid = GUID { - guid_prefix: GuidPrefix::new(&[1; 12]), + prefix: GuidPrefix::new(&[1; 12]), entity_id: EntityId::create_custom_entity_id( [1; 3], EntityKind::WRITER_WITH_KEY_USER_DEFINED, ), }; let mr_state = MessageReceiverState { - source_guid_prefix: writer_guid.guid_prefix, + source_guid_prefix: writer_guid.prefix, ..Default::default() }; reader.matched_writer_add( @@ -1720,7 +1720,7 @@ mod tests { entity_id: EntityId::create_custom_entity_id([1; 3], EntityKind::WRITER_WITH_KEY_USER_DEFINED), }; let mut mr_state = MessageReceiverState::default(); - mr_state.source_guid_prefix = writer_guid.guid_prefix; + mr_state.source_guid_prefix = writer_guid.prefix; reader.matched_writer_add( writer_guid.clone(), EntityId::UNKNOWN, diff --git a/src/dds/writer.rs b/src/dds/writer.rs index bc20f6c6..0300b07f 100644 --- a/src/dds/writer.rs +++ b/src/dds/writer.rs @@ -260,14 +260,14 @@ impl Writer { } pub fn local_readers(&self) -> Vec { - let min = GUID::new_with_prefix_and_id(self.my_guid.guid_prefix, EntityId::MIN); - let max = GUID::new_with_prefix_and_id(self.my_guid.guid_prefix, EntityId::MAX); + let min = GUID::new_with_prefix_and_id(self.my_guid.prefix, EntityId::MIN); + let max = GUID::new_with_prefix_and_id(self.my_guid.prefix, EntityId::MAX); self .readers .range((Included(min), Included(max))) .filter_map(|(guid, _)| { - if guid.guid_prefix == self.my_guid.guid_prefix { + if guid.prefix == self.my_guid.prefix { Some(guid.entity_id) } else { None @@ -407,7 +407,7 @@ impl Writer { let liveliness_flag = false; let data_hb_message = data_hb_message_builder .heartbeat_msg(self, EntityId::UNKNOWN, final_flag, liveliness_flag) - .add_header_and_build(self.my_guid.guid_prefix); + .add_header_and_build(self.my_guid.prefix); self.send_message_to_readers( DeliveryMode::Multicast, &data_hb_message, @@ -543,7 +543,7 @@ impl Writer { let hb_message = MessageBuilder::new() .ts_msg(self.endianness, Some(Timestamp::now())) .heartbeat_msg(self, EntityId::UNKNOWN, final_flag, liveliness_flag) - .add_header_and_build(self.my_guid.guid_prefix); + .add_header_and_build(self.my_guid.prefix); debug!( "Writer {:?} topic={:} HEARTBEAT {:?}", self.guid().entity_id, @@ -698,7 +698,7 @@ impl Writer { // Note: The reader_proxy is now removed from readers map let reader_guid = reader_proxy.remote_reader_guid; let mut partial_message = MessageBuilder::new() - .dst_submessage(self.endianness, reader_guid.guid_prefix) + .dst_submessage(self.endianness, reader_guid.prefix) .ts_msg(self.endianness, Some(Timestamp::now())); // TODO: This timestamp should probably not be // the current (retransmit) time, but the initial sample production timestamp, @@ -753,7 +753,7 @@ impl Writer { partial_message = partial_message.gap_msg(&BTreeSet::from_iter(no_longer_relevant), self, reader_guid); } - let data_gap_msg = partial_message.add_header_and_build(self.my_guid.guid_prefix); + let data_gap_msg = partial_message.add_header_and_build(self.my_guid.prefix); self.send_message_to_readers( DeliveryMode::Unicast, diff --git a/src/discovery/data_types/spdp_participant_data.rs b/src/discovery/data_types/spdp_participant_data.rs index 5500155a..cbb695b4 100644 --- a/src/discovery/data_types/spdp_participant_data.rs +++ b/src/discovery/data_types/spdp_participant_data.rs @@ -59,7 +59,7 @@ impl SpdpDiscoveredParticipantData { entity_id: Option, ) -> RtpsReaderProxy { let remote_reader_guid = GUID::new_with_prefix_and_id( - self.participant_guid.guid_prefix, + self.participant_guid.prefix, match entity_id { Some(id) => id, None => EntityId::SPDP_BUILTIN_PARTICIPANT_READER, @@ -89,7 +89,7 @@ impl SpdpDiscoveredParticipantData { entity_id: Option, ) -> RtpsWriterProxy { let remote_writer_guid = GUID::new_with_prefix_and_id( - self.participant_guid.guid_prefix, + self.participant_guid.prefix, match entity_id { Some(id) => id, None => EntityId::SPDP_BUILTIN_PARTICIPANT_WRITER, diff --git a/src/discovery/discovery.rs b/src/discovery/discovery.rs index fb4eed2f..a78d6660 100644 --- a/src/discovery/discovery.rs +++ b/src/discovery/discovery.rs @@ -802,7 +802,7 @@ impl Discovery { // This will read the participant from Discovery DB and construct // ReaderProxy and WriterProxy objects for built-in Readers and Writers self.send_discovery_notification(DiscoveryNotificationType::ParticipantUpdated { - guid_prefix: dp.guid().guid_prefix, + guid_prefix: dp.guid().prefix, }); // insert a (fake) reader proxy as multicast address, so discovery notifications @@ -838,10 +838,7 @@ impl Discovery { content_filter: None, }; - let writer_guid = GUID::new( - dp.guid().guid_prefix, - EntityId::SPDP_BUILTIN_PARTICIPANT_WRITER, - ); + let writer_guid = GUID::new(dp.guid().prefix, EntityId::SPDP_BUILTIN_PARTICIPANT_WRITER); let writer_proxy = WriterProxy::new( writer_guid, @@ -901,7 +898,7 @@ impl Discovery { let was_new = self .discovery_db_write() .update_participant(&participant_data); - let guid_prefix = participant_data.participant_guid.guid_prefix; + let guid_prefix = participant_data.participant_guid.prefix; self.send_discovery_notification(DiscoveryNotificationType::ParticipantUpdated { guid_prefix, }); @@ -917,12 +914,12 @@ impl Discovery { } } // Err means that DomainParticipant was disposed - Err(guid) => { + Err(data_key) => { self .discovery_db_write() - .remove_participant(guid.0.guid_prefix); + .remove_participant(data_key.0.prefix); self.send_discovery_notification(DiscoveryNotificationType::ParticipantLost { - guid_prefix: guid.0.guid_prefix, + guid_prefix: data_key.0.prefix, }); } }, @@ -961,7 +958,7 @@ impl Discovery { let mut db = self.discovery_db_write(); trace!("handle_subscription_reader discovered {:?}", &d); if read_history - .map(|e| e == d.reader_proxy.remote_reader_guid.guid_prefix) + .map(|e| e == d.reader_proxy.remote_reader_guid.prefix) .unwrap_or(true) { if let Some((drd, rtps_reader_proxy)) = db.update_subscription(&d) { diff --git a/src/discovery/discovery_db.rs b/src/discovery/discovery_db.rs index 295dc29a..e4864d66 100644 --- a/src/discovery/discovery_db.rs +++ b/src/discovery/discovery_db.rs @@ -100,7 +100,7 @@ impl DiscoveryDB { // } let mut new_participant = false; - if self.participant_proxies.get(&guid.guid_prefix).is_none() { + if self.participant_proxies.get(&guid.prefix).is_none() { info!("New remote participant: {:?}", &data); new_participant = true; if guid == self.my_guid { @@ -112,12 +112,10 @@ impl DiscoveryDB { } } // actual work here: - self - .participant_proxies - .insert(guid.guid_prefix, data.clone()); + self.participant_proxies.insert(guid.prefix, data.clone()); self .participant_last_life_signs - .insert(guid.guid_prefix, Instant::now()); + .insert(guid.prefix, Instant::now()); new_participant } @@ -321,7 +319,7 @@ impl DiscoveryDB { self.external_topic_readers.insert(guid, data.clone()); // fill in the default locators, in case DRD did not provide any let default_locator_lists = self - .find_participant_proxy(guid.guid_prefix) + .find_participant_proxy(guid.prefix) .map(|pp| { debug!("Added default locators to Reader {:?}", guid); ( @@ -330,12 +328,12 @@ impl DiscoveryDB { ) }) .unwrap_or_else(|| { - if guid.guid_prefix != GuidPrefix::UNKNOWN { + if guid.prefix != GuidPrefix::UNKNOWN { // This is normal, since we might not know about the participant yet. debug!( "No remote participant known for {:?}\nSearched with {:?} in {:?}", data, - guid.guid_prefix, + guid.prefix, self.participant_proxies.keys() ); } diff --git a/src/lib.rs b/src/lib.rs index a0f9059e..ff3824ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -177,7 +177,6 @@ pub use serialization::{ CDRDeserializerAdapter, CDRSerializerAdapter, CdrDeserializer, CdrSerializer, }; pub use structure::{duration::Duration, guid::GUID, time::Timestamp}; - // re-export from a helper crate pub use cdr_encoding_size::CdrEncodingSize; diff --git a/src/messages/submessages/info_destination.rs b/src/messages/submessages/info_destination.rs index 26004259..cc93e96f 100644 --- a/src/messages/submessages/info_destination.rs +++ b/src/messages/submessages/info_destination.rs @@ -58,7 +58,7 @@ mod tests { info_destination, InfoDestination { guid_prefix: GuidPrefix { - entity_key: [0x01, 0x02, 0x6D, 0x3F, + bytes: [0x01, 0x02, 0x6D, 0x3F, 0x7E, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00] } diff --git a/src/messages/submessages/info_source.rs b/src/messages/submessages/info_source.rs index 2b4afc23..05e0c28a 100644 --- a/src/messages/submessages/info_source.rs +++ b/src/messages/submessages/info_source.rs @@ -34,7 +34,7 @@ mod tests { vendor_id: [0xFF, 0xAA] }, guid_prefix: GuidPrefix { - entity_key: [0x01, 0x02, 0x6D, 0x3F, + bytes: [0x01, 0x02, 0x6D, 0x3F, 0x7E, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00] } diff --git a/src/ros2/builtin_datatypes.rs b/src/ros2/builtin_datatypes.rs index c2ba3cbd..65eb76df 100644 --- a/src/ros2/builtin_datatypes.rs +++ b/src/ros2/builtin_datatypes.rs @@ -17,7 +17,7 @@ pub struct Gid { impl Gid { pub fn from_guid(guid: GUID) -> Gid { let mut data: [u8; 24] = [0; 24]; - data[..12].clone_from_slice(&guid.guid_prefix.prefix_bytes); + data[..12].clone_from_slice(&guid.prefix.bytes); data[12..15].clone_from_slice(&guid.entity_id.entity_key); data[15..16].clone_from_slice(&[u8::from(guid.entity_id.entity_kind)]); Gid { data } diff --git a/src/structure/entity.rs b/src/structure/entity.rs index 0d804ecc..22a69829 100644 --- a/src/structure/entity.rs +++ b/src/structure/entity.rs @@ -13,6 +13,6 @@ pub trait RTPSEntity { self.guid().entity_id } fn guid_prefix(&self) -> GuidPrefix { - self.guid().guid_prefix + self.guid().prefix } } diff --git a/src/structure/guid.rs b/src/structure/guid.rs index 94a7c7bd..45c214cd 100644 --- a/src/structure/guid.rs +++ b/src/structure/guid.rs @@ -15,44 +15,38 @@ use crate::dds::traits::key::Key; Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash, Serialize, Deserialize, CdrEncodingSize, )] pub struct GuidPrefix { - pub(crate) prefix_bytes: [u8; 12], + pub(crate) bytes: [u8; 12], } impl GuidPrefix { - pub const UNKNOWN: GuidPrefix = GuidPrefix { - prefix_bytes: [0x00; 12], - }; + pub const UNKNOWN: GuidPrefix = GuidPrefix { bytes: [0x00; 12] }; pub fn new(prefix: &[u8]) -> GuidPrefix { - let mut pr: [u8; 12] = [0; 12]; + let mut bytes: [u8; 12] = [0; 12]; for (ix, data) in prefix.iter().enumerate() { if ix >= 12 { break; } - pr[ix] = *data; + bytes[ix] = *data; } - GuidPrefix { prefix_bytes: pr } - } - - pub fn as_slice(&self) -> &[u8] { - &self.prefix_bytes + GuidPrefix { bytes } } pub fn random_for_this_participant() -> GuidPrefix { - let mut prefix_bytes: [u8; 12] = rand::random(); // start with random data + let mut bytes: [u8; 12] = rand::random(); // start with random data // The prefix is arbitrary, but let's place our vendor id at the head // for easy recognition. It seems some other RTPS implementations are doing the // same. let my_vendor_id_bytes = crate::messages::vendor_id::VendorId::THIS_IMPLEMENTATION.as_bytes(); - prefix_bytes[0] = my_vendor_id_bytes[0]; - prefix_bytes[1] = my_vendor_id_bytes[1]; + bytes[0] = my_vendor_id_bytes[0]; + bytes[1] = my_vendor_id_bytes[1]; // TODO: // We could add some other identifying stuff here also, like one of // our IP addresses (but which one?) - GuidPrefix { prefix_bytes } + GuidPrefix { bytes } } pub fn range(&self) -> impl RangeBounds { @@ -60,10 +54,16 @@ impl GuidPrefix { } } +impl AsRef<[u8]> for GuidPrefix { + fn as_ref(&self) -> &[u8] { + &self.bytes + } +} + impl fmt::Debug for GuidPrefix { // This is so common that we skip all the inroductions and just print the data. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.prefix_bytes.fmt(f) + self.bytes.fmt(f) } } @@ -77,8 +77,8 @@ impl<'a, C: Context> Readable<'a, C> for GuidPrefix { #[inline] fn read_from>(reader: &mut R) -> Result { let mut guid_prefix = GuidPrefix::default(); - for i in 0..guid_prefix.prefix_bytes.len() { - guid_prefix.prefix_bytes[i] = reader.read_u8()?; + for i in 0..guid_prefix.bytes.len() { + guid_prefix.bytes[i] = reader.read_u8()?; } Ok(guid_prefix) } @@ -92,7 +92,7 @@ impl<'a, C: Context> Readable<'a, C> for GuidPrefix { impl Writable for GuidPrefix { #[inline] fn write_to>(&self, writer: &mut T) -> Result<(), C::Error> { - for elem in &self.prefix_bytes { + for elem in &self.bytes { writer.write_u8(*elem)?; } Ok(()) @@ -467,13 +467,13 @@ pub struct GUID { // Note: It is important to have guid_prefix first, so that derive'd Ord trait // will produce ordering, where GUIDs with same GuidPrefix are grouped // together. - pub guid_prefix: GuidPrefix, + pub prefix: GuidPrefix, pub entity_id: EntityId, } impl GUID { pub const GUID_UNKNOWN: GUID = GUID { - guid_prefix: GuidPrefix::UNKNOWN, + prefix: GuidPrefix::UNKNOWN, entity_id: EntityId::UNKNOWN, }; @@ -485,14 +485,14 @@ impl GUID { /// Generates new GUID for Participant when `guid_prefix` is random pub fn new_participant_guid() -> GUID { GUID { - guid_prefix: GuidPrefix::random_for_this_participant(), + prefix: GuidPrefix::random_for_this_participant(), entity_id: EntityId::PARTICIPANT, } } pub fn dummy_test_guid(entity_kind: EntityKind) -> GUID { GUID { - guid_prefix: GuidPrefix::new(b"FakeTestGUID"), + prefix: GuidPrefix::new(b"FakeTestGUID"), entity_id: EntityId { entity_key: [1, 2, 3], entity_kind, @@ -501,19 +501,17 @@ impl GUID { } /// Generates GUID for specific entity_id from current prefix + #[must_use] pub fn from_prefix(self, entity_id: EntityId) -> GUID { GUID { - guid_prefix: self.guid_prefix, + prefix: self.prefix, entity_id, } } /// Creates GUID from known values pub fn new_with_prefix_and_id(prefix: GuidPrefix, entity_id: EntityId) -> GUID { - GUID { - guid_prefix: prefix, - entity_id, - } + GUID { prefix, entity_id } } pub fn as_usize(&self) -> usize { @@ -527,7 +525,7 @@ impl fmt::Debug for GUID { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_fmt(format_args!( "GUID {{{:?} {:?}}}", - self.guid_prefix, self.entity_id + self.prefix, self.entity_id )) } } @@ -610,7 +608,7 @@ mod tests { { guid_prefix_endianness_insensitive, GuidPrefix { - entity_key: [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, + bytes: [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB] }, le = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, @@ -705,7 +703,7 @@ mod tests { assert_eq!( GUID { entity_id: EntityId::UNKNOWN, - guid_prefix: GuidPrefix::UNKNOWN + prefix: GuidPrefix::UNKNOWN }, GUID::GUID_UNKNOWN ); diff --git a/src/test/test_data.rs b/src/test/test_data.rs index 9cb689d4..bb85a5d9 100644 --- a/src/test/test_data.rs +++ b/src/test/test_data.rs @@ -365,8 +365,8 @@ pub(crate) fn create_rtps_data_message( let tdata = Bytes::from(to_bytes::(&data).unwrap()); let mut rtps_message = Message::default(); - let prefix = GUID::dummy_test_guid(EntityKind::UNKNOWN_BUILT_IN); - let rtps_message_header = Header::new(prefix.guid_prefix); + let guid = GUID::dummy_test_guid(EntityKind::UNKNOWN_BUILT_IN); + let rtps_message_header = Header::new(guid.prefix); rtps_message.set_header(rtps_message_header); let serialized_payload = SerializedPayload {