]> git.lizzy.rs Git - mt_rudp.git/blobdiff - src/common.rs
Implement sending splits
[mt_rudp.git] / src / common.rs
index 0ed08f3c3b09c8f3e28647710c3c688f764e65a9..9d99cb9e7b689780b6e411256d48ed025b0ca1b6 100644 (file)
@@ -20,11 +20,6 @@ pub trait UdpReceiver: Send {
     async fn recv(&mut self) -> io::Result<Vec<u8>>;
 }
 
-pub trait UdpPeer {
-    type Sender: UdpSender;
-    type Receiver: UdpReceiver;
-}
-
 #[derive(Debug, Copy, Clone, PartialEq)]
 #[repr(u16)]
 pub enum PeerID {
@@ -57,3 +52,17 @@ pub struct Pkt<'a> {
     pub chan: u8,
     pub data: Cow<'a, [u8]>,
 }
+
+impl<'a> Pkt<'a> {
+    pub fn size(&self) -> usize {
+        self.header_size() + self.body_size()
+    }
+
+    pub fn body_size(&self) -> usize {
+        self.data.len()
+    }
+
+    pub fn header_size(&self) -> usize {
+        4 + 2 + 1 + if self.unrel { 0 } else { 1 + 2 } + 1
+    }
+}