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

feat(Publisher): implement the send_with_time() method #9

Merged
merged 2 commits into from
Feb 20, 2023
Merged
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
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use std::{
env, ffi,
marker::PhantomData,
os::raw::{c_char, c_int, c_long, c_void},
os::raw::{c_char, c_int, c_long, c_void, c_longlong},
ptr, slice,
time::{Duration, Instant},
};
Expand Down Expand Up @@ -257,6 +257,11 @@ where
}

pub fn send(&self, msg: &T) -> Result<()> {
self.send_with_time(msg, -1)
}

/// Same as [send](#method.send) but let the caller set the time of the message
pub fn send_with_time(&self, msg: &T, time: i64) -> Result<()> {
let mut buf = Vec::with_capacity(32);
S::serialize(msg, &mut buf)?;

Expand All @@ -266,7 +271,7 @@ where
self.handle,
buf.as_ptr() as *const c_void,
bytes_expected as c_int,
-1,
time as c_longlong,
)
};
log::trace!("Published {} / {} bytes", bytes_sent, bytes_expected);
Expand Down