use core::{
fmt::{Debug, Formatter},
hash::{Hash, Hasher},
};
use ts_keys::NodePublicKey;
use crate::{Message, MessageType};
#[derive(
zerocopy::Immutable,
zerocopy::FromBytes,
zerocopy::IntoBytes,
zerocopy::Unaligned,
zerocopy::KnownLayout,
)]
#[repr(C, packed)]
pub struct Ping {
pub tx_id: [u8; 12],
pub node_key: NodePublicKey,
pub padding: [u8],
}
impl Message for Ping {
const TYPE: MessageType = MessageType::Ping;
}
impl Ping {
pub const fn size_with_padding(n: usize) -> usize {
12 + size_of::<NodePublicKey>() + n
}
}
impl Debug for &Ping {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Ping")
.field("tx_id", &self.tx_id)
.field("node_key", &self.node_key)
.field("padding", &&self.padding)
.finish()
}
}
impl PartialEq for &Ping {
fn eq(&self, other: &Self) -> bool {
self.tx_id == other.tx_id
&& self.node_key == other.node_key
&& self.padding == other.padding
}
}
impl Eq for &Ping {}
impl Hash for &Ping {
fn hash<H: Hasher>(&self, state: &mut H) {
self.tx_id.hash(state);
self.node_key.hash(state);
self.padding.hash(state);
}
}