Skip to content

Commit

Permalink
iox-#64 Use 'usize' as return type for chunk header methods
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Sep 17, 2023
1 parent 7aaa01d commit f7573d8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
8 changes: 4 additions & 4 deletions iceoryx-sys/src/chunk_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ impl ChunkHeader {
}
}

pub fn get_user_payload_size(&self) -> u32 {
pub fn get_user_payload_size(&self) -> usize {
unsafe {
cpp!([self as "ChunkHeader*"] -> u32 as "uint32_t" {
return self->userPayloadSize();
})
}) as usize
}
}

pub fn get_user_payload_alignment(&self) -> u32 {
pub fn get_user_payload_alignment(&self) -> usize {
unsafe {
cpp!([self as "ChunkHeader*"] -> u32 as "uint32_t" {
return self->userPayloadAlignment();
})
}) as usize
}
}
}
11 changes: 4 additions & 7 deletions iceoryx-sys/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,12 @@ impl Subscriber {
let chunk_header = payload.chunk_header();
let payload_size = chunk_header.get_user_payload_size();
let payload_alignment = chunk_header.get_user_payload_alignment();
let len = payload_size as usize / std::mem::size_of::<T>();
let len = payload_size / std::mem::size_of::<T>();

if payload_size as usize % std::mem::size_of::<T>() == 0
&& payload_alignment as usize >= std::mem::align_of::<T>()
if payload_size % std::mem::size_of::<T>() == 0
&& payload_alignment >= std::mem::align_of::<T>()
{
Some(RawSample::slice_from_raw_parts(
payload.cast::<T>(),
len as usize,
))
Some(RawSample::slice_from_raw_parts(payload.cast::<T>(), len))
} else {
// TODO return Result<Option<T>>
self.release(payload);
Expand Down
4 changes: 2 additions & 2 deletions src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl<S: ffi::SubscriberStrongRef> Sample<[u8], S> {
/// The caller must ensure that the [u8] is actually a T. It is undefined behavior if the underlying data is not a T.
pub unsafe fn try_as<T: ShmSend>(&self) -> Option<&T> {
let chunk_header = self.data.chunk_header();
let payload_size = chunk_header.get_user_payload_size() as usize;
let payload_alignment = chunk_header.get_user_payload_alignment() as usize;
let payload_size = chunk_header.get_user_payload_size();
let payload_alignment = chunk_header.get_user_payload_alignment();

if payload_size >= std::mem::size_of::<T>()
&& payload_alignment >= std::mem::align_of::<T>()
Expand Down
4 changes: 2 additions & 2 deletions src/sample_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ impl<'a> SampleMut<'a, [MaybeUninit<u8>]> {
pub fn try_as_uninit<T: ShmSend>(&mut self) -> Option<&mut MaybeUninit<T>> {
unsafe {
let chunk_header = self.data.chunk_header();
let payload_size = chunk_header.get_user_payload_size() as usize;
let payload_alignment = chunk_header.get_user_payload_alignment() as usize;
let payload_size = chunk_header.get_user_payload_size();
let payload_alignment = chunk_header.get_user_payload_alignment();

if payload_size >= std::mem::size_of::<T>()
&& payload_alignment >= std::mem::align_of::<T>()
Expand Down

0 comments on commit f7573d8

Please sign in to comment.