From 0621e87370fb0f16e943539b5fe4a7296440ebd7 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Quiros Date: Tue, 4 Oct 2022 16:04:12 +0200 Subject: [PATCH] Added content topic, update pubsub topic --- waku/src/general/mod.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/waku/src/general/mod.rs b/waku/src/general/mod.rs index 3a90695..602bd8b 100644 --- a/waku/src/general/mod.rs +++ b/waku/src/general/mod.rs @@ -170,21 +170,21 @@ impl RegexRepresentation for Encoding { const REGEX: &'static str = r"\w"; } -pub struct WakuPubsubTopic { +pub struct WakuContentTopic { application_name: String, version: usize, content_topic_name: String, encoding: Encoding, } -impl FromStr for WakuPubsubTopic { +impl FromStr for WakuContentTopic { type Err = String; 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, usize, String, Encoding) { - Ok(WakuPubsubTopic { + Ok(WakuContentTopic { application_name, version, content_topic_name, @@ -200,3 +200,28 @@ impl FromStr for WakuPubsubTopic { } } } + +pub struct WakuPubSubTopic { + topic_name: String, + encoding: Encoding, +} + +impl FromStr for WakuPubSubTopic { + type Err = String; + + fn from_str(s: &str) -> std::result::Result { + if let Ok((topic_name, encoding)) = scanf!(s, "/waku/v2/{}/{}", String, Encoding) { + Ok(WakuPubSubTopic { + topic_name, + encoding, + }) + } else { + Err( + format!( + "Wrong pub-sub topic format. Should be `/{{application-name}}/{{version-of-the-application}}/{{content-topic-name}}/{{encoding}}`. Got: {}", + s + ) + ) + } + } +}