2020-12-11 14:53:59 +00:00
|
|
|
use std::net::IpAddr;
|
|
|
|
|
2020-12-02 12:30:47 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
pub type MessageKind = u32;
|
|
|
|
|
2020-12-02 19:12:24 +00:00
|
|
|
/// This trait should be implemented by all messages your application
|
|
|
|
/// wants to handle (click to read more).
|
|
|
|
///
|
|
|
|
/// It defines a `KIND`, which should be a **unique**
|
|
|
|
/// `u32` that distinguishes these messages from other types of messages
|
|
|
|
/// (it is used by our communication protocol), as well as an associated
|
|
|
|
/// `Response` type that defines the type of the response that is given
|
|
|
|
/// to the message. It is your responsibility to ensure that `KIND` is a
|
|
|
|
/// unique `u32` that is not used by any other protocol messages.
|
|
|
|
/// All `KIND` values of the form `0x42xxxxxx` are reserved by the netapp
|
|
|
|
/// crate for internal purposes.
|
|
|
|
///
|
|
|
|
/// A handler for this message has type `Self -> Self::Response`.
|
|
|
|
/// If you need to return an error, the `Response` type should be
|
|
|
|
/// a `Result<_, _>`.
|
2020-12-02 12:30:47 +00:00
|
|
|
pub trait Message: Serialize + for<'de> Deserialize<'de> + Send + Sync {
|
|
|
|
const KIND: MessageKind;
|
|
|
|
type Response: Serialize + for<'de> Deserialize<'de> + Send + Sync;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub(crate) struct HelloMessage {
|
2020-12-11 14:53:59 +00:00
|
|
|
pub server_addr: Option<IpAddr>,
|
2020-12-02 12:30:47 +00:00
|
|
|
pub server_port: u16,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Message for HelloMessage {
|
|
|
|
const KIND: MessageKind = 0x42000001;
|
|
|
|
type Response = ();
|
|
|
|
}
|