-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtypes.rs
More file actions
30 lines (26 loc) · 791 Bytes
/
types.rs
File metadata and controls
30 lines (26 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! Types used by the pub/sub layer of eCAL.
use rustecal_sys::*;
use rustecal_core::types::EntityId;
use std::ffi::CStr;
/// Internal eCAL topic identifier, used by publishers and subscribers.
#[derive(Debug, Clone)]
pub struct TopicId {
pub entity_id: EntityId,
pub topic_name: String,
}
impl From<eCAL_STopicId> for TopicId {
fn from(raw: eCAL_STopicId) -> Self {
Self {
entity_id: EntityId::from(raw.topic_id),
topic_name: cstr_to_string(raw.topic_name),
}
}
}
/// Helper function to safely convert a null-terminated C string.
fn cstr_to_string(ptr: *const std::os::raw::c_char) -> String {
if ptr.is_null() {
String::new()
} else {
unsafe { CStr::from_ptr(ptr).to_string_lossy().into_owned() }
}
}