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

fix: re-expose methods required by Python API #161

Merged
merged 1 commit into from
May 3, 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
26 changes: 26 additions & 0 deletions zenoh-flow/src/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ impl Payload {
}
}
}

/// Return an [Arc] containing the bytes representation of the [Payload].
///
/// # Performance
///
/// This method will only serialize (and thus allocate) the [Payload] if it is typed. Otherwise
/// the [Arc] is cloned.
//
// NOTE: This method is used by, at least, our Python API.
pub fn try_as_gytes(&self) -> Result<Arc<Vec<u8>>> {
match self {
Payload::Bytes(bytes) => Ok(bytes.clone()),
Payload::Typed((typed_data, serializer)) => {
let mut buffer = Vec::default();
(serializer)(&mut buffer, Arc::clone(typed_data))?;
Ok(Arc::new(buffer))
}
}
}
}

/// Creates a new `Data` from a `Vec<u8>`.
Expand Down Expand Up @@ -151,6 +170,13 @@ impl DataMessage {
timestamp,
}
}

/// Return the [Timestamp] associated with this [DataMessage].
//
// NOTE: This method is used by, at least, our Python API.
pub fn get_timestamp(&self) -> &Timestamp {
&self.timestamp
}
}

/// Metadata stored in Zenoh's time series storages.
Expand Down