refactor: remove getters
This commit is contained in:
parent
9d3b575037
commit
c434e9ebf5
|
@ -24,19 +24,19 @@ pub type Result<T> = std::result::Result<T, String>;
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct WakuMessage {
|
||||
#[serde(with = "base64_serde", default = "Vec::new")]
|
||||
payload: Vec<u8>,
|
||||
pub payload: Vec<u8>,
|
||||
/// The content topic to be set on the message
|
||||
content_topic: WakuContentTopic,
|
||||
pub content_topic: WakuContentTopic,
|
||||
/// The Waku Message version number
|
||||
#[serde(default)]
|
||||
version: WakuMessageVersion,
|
||||
pub version: WakuMessageVersion,
|
||||
/// Unix timestamp in nanoseconds
|
||||
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||
timestamp: usize,
|
||||
pub timestamp: usize,
|
||||
#[serde(with = "base64_serde", default = "Vec::new")]
|
||||
meta: Vec<u8>,
|
||||
pub meta: Vec<u8>,
|
||||
#[serde(default)]
|
||||
ephemeral: bool,
|
||||
pub ephemeral: bool,
|
||||
// TODO: implement RLN fields
|
||||
#[serde(flatten)]
|
||||
_extras: serde_json::Value,
|
||||
|
@ -64,30 +64,6 @@ impl WakuMessage {
|
|||
_extras: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn payload(&self) -> &[u8] {
|
||||
&self.payload
|
||||
}
|
||||
|
||||
pub fn content_topic(&self) -> &WakuContentTopic {
|
||||
&self.content_topic
|
||||
}
|
||||
|
||||
pub fn version(&self) -> WakuMessageVersion {
|
||||
self.version
|
||||
}
|
||||
|
||||
pub fn timestamp(&self) -> usize {
|
||||
self.timestamp
|
||||
}
|
||||
|
||||
pub fn meta(&self) -> &[u8] {
|
||||
&self.meta
|
||||
}
|
||||
|
||||
pub fn ephemeral(&self) -> bool {
|
||||
self.ephemeral
|
||||
}
|
||||
}
|
||||
|
||||
/// WakuMessage encoding scheme
|
||||
|
|
|
@ -29,25 +29,11 @@ pub enum Event {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct WakuMessageEvent {
|
||||
/// The pubsub topic on which the message was received
|
||||
pubsub_topic: String,
|
||||
pub pubsub_topic: String,
|
||||
/// The message id
|
||||
message_id: MessageId,
|
||||
pub message_id: MessageId,
|
||||
/// The message in [`WakuMessage`] format
|
||||
waku_message: WakuMessage,
|
||||
}
|
||||
|
||||
impl WakuMessageEvent {
|
||||
pub fn pubsub_topic(&self) -> &String {
|
||||
&self.pubsub_topic
|
||||
}
|
||||
|
||||
pub fn message_id(&self) -> &String {
|
||||
&self.message_id
|
||||
}
|
||||
|
||||
pub fn waku_message(&self) -> &WakuMessage {
|
||||
&self.waku_message
|
||||
}
|
||||
pub waku_message: WakuMessage,
|
||||
}
|
||||
|
||||
/// Register callback to act as event handler and receive application events,
|
||||
|
|
|
@ -33,9 +33,9 @@ struct Response {
|
|||
fn set_callback(node: &WakuNodeHandle, tx: Sender<Response>) {
|
||||
node.set_event_callback(move |event| {
|
||||
if let Event::WakuMessage(message) = event {
|
||||
let id = message.message_id();
|
||||
let message = message.waku_message();
|
||||
let payload = message.payload().to_vec();
|
||||
let id = message.message_id;
|
||||
let message = message.waku_message;
|
||||
let payload = message.payload.to_vec();
|
||||
|
||||
tx.send(Response {
|
||||
id: id.to_string(),
|
||||
|
|
Loading…
Reference in New Issue