From e4672df292451480ce30b3897ee046f15cb3fd14 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 8 Nov 2023 15:05:46 -0400 Subject: [PATCH] fix: content topic should accept strings --- examples/toy-chat/src/protocol.rs | 2 +- waku-bindings/src/general/mod.rs | 12 ++++++------ waku-bindings/tests/node.rs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/toy-chat/src/protocol.rs b/examples/toy-chat/src/protocol.rs index 501ad85..3652953 100644 --- a/examples/toy-chat/src/protocol.rs +++ b/examples/toy-chat/src/protocol.rs @@ -3,7 +3,7 @@ use prost::Message; use waku_bindings::{Encoding, WakuContentTopic}; pub static TOY_CHAT_CONTENT_TOPIC: WakuContentTopic = - WakuContentTopic::new("toy-chat", 2, "huilong", Encoding::Proto); + WakuContentTopic::new("toy-chat", "2", "huilong", Encoding::Proto); #[derive(Clone, Message)] pub struct Chat2Message { diff --git a/waku-bindings/src/general/mod.rs b/waku-bindings/src/general/mod.rs index 4214fd1..0de4b62 100644 --- a/waku-bindings/src/general/mod.rs +++ b/waku-bindings/src/general/mod.rs @@ -442,7 +442,7 @@ impl RegexRepresentation for Encoding { #[derive(Clone, Debug, Eq, PartialEq)] pub struct WakuContentTopic { pub application_name: Cow<'static, str>, - pub version: usize, + pub version: Cow<'static, str>, pub content_topic_name: Cow<'static, str>, pub encoding: Encoding, } @@ -450,13 +450,13 @@ pub struct WakuContentTopic { impl WakuContentTopic { pub const fn new( application_name: &'static str, - version: usize, + version: &'static str, content_topic_name: &'static str, encoding: Encoding, ) -> Self { Self { application_name: Cow::Borrowed(application_name), - version, + version: Cow::Borrowed(version), content_topic_name: Cow::Borrowed(content_topic_name), encoding, } @@ -468,11 +468,11 @@ impl FromStr for WakuContentTopic { fn from_str(s: &str) -> std::result::Result { if let Ok((application_name, version, content_topic_name, encoding)) = - scanf!(s, "/{}/{}/{}/{:/.+?/}", String, usize, String, Encoding) + scanf!(s, "/{}/{}/{}/{:/.+?/}", String, String, String, Encoding) { Ok(WakuContentTopic { application_name: Cow::Owned(application_name), - version, + version: Cow::Owned(version), content_topic_name: Cow::Owned(content_topic_name), encoding, }) @@ -600,7 +600,7 @@ mod tests { #[test] fn encode_decode() { - let content_topic = WakuContentTopic::new("hello", 2, "world", Encoding::Proto); + let content_topic = WakuContentTopic::new("hello", "2", "world", Encoding::Proto); let message = WakuMessage::new( "hello", content_topic, diff --git a/waku-bindings/tests/node.rs b/waku-bindings/tests/node.rs index eeb1001..8a69e69 100644 --- a/waku-bindings/tests/node.rs +++ b/waku-bindings/tests/node.rs @@ -159,7 +159,7 @@ async fn discv5_echo() -> Result<(), String> { // Subscribe to default channel. let content_filter = ContentFilter::new(Some(waku_default_pubsub_topic()), vec![]); node.relay_subscribe(&content_filter)?; - let content_topic = WakuContentTopic::new("toychat", 2, "huilong", Encoding::Proto); + let content_topic = WakuContentTopic::new("toychat", "2", "huilong", Encoding::Proto); let topics = node.relay_topics()?; let default_topic = waku_default_pubsub_topic(); @@ -218,7 +218,7 @@ async fn default_echo() -> Result<(), String> { // subscribe to default channel let content_filter = ContentFilter::new(Some(waku_default_pubsub_topic()), vec![]); node.relay_subscribe(&content_filter)?; - let content_topic = WakuContentTopic::new("toychat", 2, "huilong", Encoding::Proto); + let content_topic = WakuContentTopic::new("toychat", "2", "huilong", Encoding::Proto); let sleep = time::sleep(Duration::from_secs(ECHO_TIMEOUT)); tokio::pin!(sleep);