adding header destructors
This commit is contained in:
parent
46ad3068d2
commit
2c2fc7924b
@ -31,3 +31,9 @@ impl Command for Authenticate {
|
||||
8
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Authenticate> for ([u8; 8],) {
|
||||
fn from(auth: Authenticate) -> Self {
|
||||
(auth.token,)
|
||||
}
|
||||
}
|
||||
|
@ -31,3 +31,9 @@ impl Command for Connect {
|
||||
self.addr.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Connect> for (Address,) {
|
||||
fn from(connect: Connect) -> Self {
|
||||
(connect.addr,)
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ impl Dissociate {
|
||||
Self { assoc_id }
|
||||
}
|
||||
|
||||
pub fn assoc_id(&self) -> u16 {
|
||||
self.assoc_id
|
||||
pub fn assoc_id(&self) -> &u16 {
|
||||
&self.assoc_id
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,3 +31,9 @@ impl Command for Dissociate {
|
||||
2
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Dissociate> for (u16,) {
|
||||
fn from(dissoc: Dissociate) -> Self {
|
||||
(dissoc.assoc_id,)
|
||||
}
|
||||
}
|
||||
|
@ -25,3 +25,9 @@ impl Command for Heartbeat {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Heartbeat> for () {
|
||||
fn from(hb: Heartbeat) -> Self {
|
||||
()
|
||||
}
|
||||
}
|
||||
|
@ -36,24 +36,24 @@ impl Packet {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assoc_id(&self) -> u16 {
|
||||
self.assoc_id
|
||||
pub fn assoc_id(&self) -> &u16 {
|
||||
&self.assoc_id
|
||||
}
|
||||
|
||||
pub fn pkt_id(&self) -> u16 {
|
||||
self.pkt_id
|
||||
pub fn pkt_id(&self) -> &u16 {
|
||||
&self.pkt_id
|
||||
}
|
||||
|
||||
pub fn frag_total(&self) -> u8 {
|
||||
self.frag_total
|
||||
pub fn frag_total(&self) -> &u8 {
|
||||
&self.frag_total
|
||||
}
|
||||
|
||||
pub fn frag_id(&self) -> u8 {
|
||||
self.frag_id
|
||||
pub fn frag_id(&self) -> &u8 {
|
||||
&self.frag_id
|
||||
}
|
||||
|
||||
pub fn size(&self) -> u16 {
|
||||
self.size
|
||||
pub fn size(&self) -> &u16 {
|
||||
&self.size
|
||||
}
|
||||
|
||||
pub fn addr(&self) -> &Address {
|
||||
@ -74,3 +74,16 @@ impl Command for Packet {
|
||||
2 + 2 + 1 + 1 + 2 + self.addr.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Packet> for (u16, u16, u8, u8, u16, Address) {
|
||||
fn from(pkt: Packet) -> Self {
|
||||
(
|
||||
pkt.assoc_id,
|
||||
pkt.pkt_id,
|
||||
pkt.frag_total,
|
||||
pkt.frag_id,
|
||||
pkt.size,
|
||||
pkt.addr,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,6 @@ struct Tx {
|
||||
_task_reg: TaskRegister,
|
||||
}
|
||||
|
||||
struct Rx;
|
||||
|
||||
impl Connect<side::Tx> {
|
||||
pub(super) fn new(task_reg: TaskRegister, addr: Address) -> Self {
|
||||
Self {
|
||||
@ -35,3 +33,17 @@ impl Connect<side::Tx> {
|
||||
&tx.header
|
||||
}
|
||||
}
|
||||
|
||||
struct Rx {
|
||||
addr: Address,
|
||||
}
|
||||
|
||||
impl Connect<side::Rx> {
|
||||
pub(super) fn new(header: ConnectHeader) -> Self {
|
||||
let (addr,) = header.into();
|
||||
Self {
|
||||
inner: Side::Rx(Rx { addr }),
|
||||
_marker: side::Rx,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::protocol::Address;
|
||||
use crate::protocol::{Address, Connect as ConnectHeader};
|
||||
use parking_lot::Mutex;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
@ -45,6 +45,10 @@ impl Connection {
|
||||
Connect::<side::Tx>::new(self.local_active_task_count.reg(), addr)
|
||||
}
|
||||
|
||||
pub fn recv_connect(&self, header: ConnectHeader) -> Connect<side::Rx> {
|
||||
Connect::<side::Rx>::new(header)
|
||||
}
|
||||
|
||||
pub fn send_packet(
|
||||
&self,
|
||||
assoc_id: u16,
|
||||
|
Loading…
x
Reference in New Issue
Block a user