fix: content topic should accept strings

This commit is contained in:
Richard Ramos 2023-11-08 15:05:46 -04:00
parent dc32f22f4a
commit e4672df292
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
3 changed files with 9 additions and 9 deletions

View File

@ -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 {

View File

@ -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<Self, Self::Err> {
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,

View File

@ -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);