Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small improvement: Make from_c_parts only visible inside crate #236

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,17 @@ impl Message {
///
/// * `topic` The topic on which the message is published.
/// * `msg` The message struct from the C library
pub fn from_c_parts(topic: CString, cmsg: &ffi::MQTTAsync_message) -> Self {
///
/// # Safety
///
/// Caller must make sure that cmsg is valid
pub(crate) unsafe fn from_c_parts(topic: CString, cmsg: &ffi::MQTTAsync_message) -> Self {
let len = cmsg.payloadlen as usize;

let payload = if cmsg.payload.is_null() {
Vec::new()
}
else {
unsafe { slice::from_raw_parts(cmsg.payload as *mut u8, len) }.to_vec()
} else {
slice::from_raw_parts(cmsg.payload as *mut u8, len).to_vec()
};

let data = MessageData {
Expand Down