Skip to content

Commit

Permalink
resolve comments: update rust comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuschen committed Oct 7, 2024
1 parent 8bdba7c commit 10ae9fd
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions iceoryx2/src/service/static_config/message_type_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,24 @@ use serde::{Deserialize, Serialize};
#[derive(Default, Debug, Clone, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub enum TypeVariant {
#[default]
/// A fixed size type which is determined during compile.
/// A structure holds some pointer fields should be clarified as Dynamic.
/// A type notated by [`#[repr(C)]`](https://doc.rust-lang.org/reference/type-layout.html#reprc).
/// with a constant size known at compile time is recognized as FixedSize.
/// The FixedSize type should satisfy the [`Sized`].
/// For example, all primitive types are FixedSize. The self-contained structs(without pointer members
/// or heap-usages) are FixedSize.
FixedSize,
/// A dynamic sized type like a slice or it contains some pointer fields.

/// A dynamic sized type strictly refers to the slice of an iceoryx2 compatible types.
/// The struct with pointer members or with heap usage MUSTN't be recognized as Dynamic type.
/// Indeed, they're the in-compatible iceoryx2 types.
///
/// The underlying reason is the shared memory which we use to store the payload data.
/// If the payload type would use the heap then the type would use
/// process local memory that is not available to another process.
///
/// The pointer requirement comes again from shared memory.
/// It has a different pointer address offset in every process rendering any absolute pointer
/// useless and dereferencing it would end up in a segfault.
Dynamic,
}

Expand All @@ -37,6 +51,15 @@ pub struct TypeDetail {
/// The size of the underlying type calculated by [`core::mem::size_of`].
pub size: usize,
/// The ABI-required minimum alignment of the underlying type calculated by [`core::mem::align_of`].
/// It may be set by users with a larger alignment, e.g the memory provided by allocator is used by SIMD.
///
/// ```
/// use iceoryx2::service::builder::publish_subscribe::Builder;
/// let service = node
/// .service_builder(&"My/Funk/ServiceName".try_into()?)
/// .publish_subscribe::<TransmissionData>()
/// .payload_alignment(256)
/// ```
pub alignment: usize,
}

Expand Down Expand Up @@ -79,7 +102,7 @@ impl MessageTypeDetails {
payload_start as *const u8
}

/// returns pointer of user_header which is the field follows the header field in a structure.
/// returns the pointer to the user header
pub(crate) fn user_header_ptr_from_header(&self, header: *const u8) -> *const u8 {
let header = header as usize;
let user_header_start = align(header + self.header.size, self.user_header.alignment);
Expand Down Expand Up @@ -136,7 +159,7 @@ mod tests {
_b: bool,
_c: i64,
}

let sut = MessageTypeDetails::from::<i32, i64, MyPayload>(TypeVariant::FixedSize);
let expected = MessageTypeDetails{
header: TypeDetail{
Expand Down

0 comments on commit 10ae9fd

Please sign in to comment.