Skip to content

Commit

Permalink
fix: re-expose methods required by Python API (#161)
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Loudet <[email protected]>
  • Loading branch information
J-Loudet committed May 3, 2023
1 parent 28d8984 commit d7d4be3
Showing 1 changed file with 26 additions and 0 deletions.
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

0 comments on commit d7d4be3

Please sign in to comment.