mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-02 14:03:12 +00:00
Relay create content/pubsub topic
This commit is contained in:
parent
0621e87370
commit
ed0c9ea19c
@ -1,6 +1,7 @@
|
||||
mod config;
|
||||
mod management;
|
||||
mod peers;
|
||||
mod relay;
|
||||
|
||||
// std
|
||||
use multiaddr::Multiaddr;
|
||||
|
||||
47
waku/src/node/relay.rs
Normal file
47
waku/src/node/relay.rs
Normal file
@ -0,0 +1,47 @@
|
||||
use crate::general::{Encoding, WakuContentTopic, WakuPubSubTopic};
|
||||
use std::ffi::{CStr, CString};
|
||||
|
||||
pub fn waku_create_content_topic(
|
||||
application_name: &str,
|
||||
application_version: usize,
|
||||
content_topic_name: &str,
|
||||
enconding: Encoding,
|
||||
) -> WakuContentTopic {
|
||||
unsafe {
|
||||
CStr::from_ptr(waku_sys::waku_content_topic(
|
||||
CString::new(application_name)
|
||||
.expect("Application name should always transform to CString")
|
||||
.into_raw(),
|
||||
application_version
|
||||
.try_into()
|
||||
.expect("Version should fit within an u32"),
|
||||
CString::new(content_topic_name)
|
||||
.expect("Conmtent topic should always transform to CString")
|
||||
.into_raw(),
|
||||
CString::new(enconding.to_string())
|
||||
.expect("Encoding should always transform to CString")
|
||||
.into_raw(),
|
||||
))
|
||||
}
|
||||
.to_str()
|
||||
.expect("&str from result should always be")
|
||||
.parse()
|
||||
.expect("Content topic data should be always parseable")
|
||||
}
|
||||
|
||||
pub fn waku_create_pubsub_topic(topic_name: &str, enconding: Encoding) -> WakuPubSubTopic {
|
||||
unsafe {
|
||||
CStr::from_ptr(waku_sys::waku_pubsub_topic(
|
||||
CString::new(topic_name)
|
||||
.expect("Topic name should always transform to CString")
|
||||
.into_raw(),
|
||||
CString::new(enconding.to_string())
|
||||
.expect("Encoding should always transform to CString")
|
||||
.into_raw(),
|
||||
))
|
||||
}
|
||||
.to_str()
|
||||
.expect("&str from result should always be")
|
||||
.parse()
|
||||
.expect("Pubsub topic data should be always parseable")
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user