@@ -20,10 +20,24 @@ use serde::{Deserialize, Serialize};
20
20
#[ derive( Default , Debug , Clone , Eq , Hash , PartialEq , Serialize , Deserialize ) ]
21
21
pub enum TypeVariant {
22
22
#[ default]
23
- /// A fixed size type which is determined during compile.
24
- /// A structure holds some pointer fields should be clarified as Dynamic.
23
+ /// A type notated by [`#[repr(C)]`](https://doc.rust-lang.org/reference/type-layout.html#reprc).
24
+ /// with a constant size known at compile time is recognized as FixedSize.
25
+ /// The FixedSize type should satisfy the [`Sized`].
26
+ /// For example, all primitive types are FixedSize. The self-contained structs(without pointer members
27
+ /// or heap-usages) are FixedSize.
25
28
FixedSize ,
26
- /// A dynamic sized type like a slice or it contains some pointer fields.
29
+
30
+ /// A dynamic sized type strictly refers to the slice of an iceoryx2 compatible types.
31
+ /// The struct with pointer members or with heap usage MUSTN't be recognized as Dynamic type.
32
+ /// Indeed, they're the in-compatible iceoryx2 types.
33
+ ///
34
+ /// The underlying reason is the shared memory which we use to store the payload data.
35
+ /// If the payload type would use the heap then the type would use
36
+ /// process local memory that is not available to another process.
37
+ ///
38
+ /// The pointer requirement comes again from shared memory.
39
+ /// It has a different pointer address offset in every process rendering any absolute pointer
40
+ /// useless and dereferencing it would end up in a segfault.
27
41
Dynamic ,
28
42
}
29
43
@@ -37,6 +51,7 @@ pub struct TypeDetail {
37
51
/// The size of the underlying type calculated by [`core::mem::size_of`].
38
52
pub size : usize ,
39
53
/// The ABI-required minimum alignment of the underlying type calculated by [`core::mem::align_of`].
54
+ /// It may be set by users with a larger alignment, e.g the memory provided by allocator used by SIMD.
40
55
pub alignment : usize ,
41
56
}
42
57
@@ -79,7 +94,7 @@ impl MessageTypeDetails {
79
94
payload_start as * const u8
80
95
}
81
96
82
- /// returns pointer of user_header which is the field follows the header field in a structure.
97
+ /// returns the pointer to the user header
83
98
pub ( crate ) fn user_header_ptr_from_header ( & self , header : * const u8 ) -> * const u8 {
84
99
let header = header as usize ;
85
100
let user_header_start = align ( header + self . header . size , self . user_header . alignment ) ;
@@ -136,7 +151,7 @@ mod tests {
136
151
_b : bool ,
137
152
_c : i64 ,
138
153
}
139
-
154
+
140
155
let sut = MessageTypeDetails :: from :: < i32 , i64 , MyPayload > ( TypeVariant :: FixedSize ) ;
141
156
let expected = MessageTypeDetails {
142
157
header : TypeDetail {
0 commit comments