mirror of
https://github.com/waku-org/waku-rust-bindings.git
synced 2025-01-12 15:44:13 +00:00
fix: handle missing ephemeral field and unknown encodings in content topics (#61)
* fix(example): only attempt to decode messages sent in the toy chat content topic * fix: handle missing ephemeral field and unknown encodings
This commit is contained in:
parent
8d825ad22e
commit
803fc37e04
@ -134,6 +134,10 @@ fn main() -> std::result::Result<(), Box<dyn Error>> {
|
||||
let shared_messages = Arc::clone(&app.messages);
|
||||
waku_set_event_callback(move |signal| match signal.event() {
|
||||
waku_bindings::Event::WakuMessage(event) => {
|
||||
if event.waku_message().content_topic() != &TOY_CHAT_CONTENT_TOPIC {
|
||||
return;
|
||||
}
|
||||
|
||||
match <Chat2Message as Message>::decode(event.waku_message().payload()) {
|
||||
Ok(chat_message) => {
|
||||
shared_messages.write().unwrap().push(chat_message);
|
||||
|
@ -91,6 +91,7 @@ pub struct WakuMessage {
|
||||
timestamp: usize,
|
||||
#[serde(with = "base64_serde", default = "Vec::new")]
|
||||
meta: Vec<u8>,
|
||||
#[serde(default)]
|
||||
ephemeral: bool,
|
||||
// TODO: implement RLN fields
|
||||
#[serde(flatten)]
|
||||
@ -310,11 +311,12 @@ pub struct MessageIndex {
|
||||
}
|
||||
|
||||
/// WakuMessage encoding scheme
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum Encoding {
|
||||
Proto,
|
||||
Rlp,
|
||||
Rfc26,
|
||||
Unknown(String),
|
||||
}
|
||||
|
||||
impl Display for Encoding {
|
||||
@ -323,6 +325,7 @@ impl Display for Encoding {
|
||||
Encoding::Proto => "proto",
|
||||
Encoding::Rlp => "rlp",
|
||||
Encoding::Rfc26 => "rfc26",
|
||||
Encoding::Unknown(value) => value,
|
||||
};
|
||||
f.write_str(s)
|
||||
}
|
||||
@ -336,10 +339,7 @@ impl FromStr for Encoding {
|
||||
"proto" => Ok(Self::Proto),
|
||||
"rlp" => Ok(Self::Rlp),
|
||||
"rfc26" => Ok(Self::Rfc26),
|
||||
encoding => Err(std::io::Error::new(
|
||||
std::io::ErrorKind::InvalidInput,
|
||||
format!("Unrecognized encoding: {encoding}"),
|
||||
)),
|
||||
encoding => Ok(Self::Unknown(encoding.to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user