change ack msg to store as array
This commit is contained in:
parent
a37edf2112
commit
6b3d8acdf1
|
@ -1,7 +1,6 @@
|
||||||
use super::seg::SegIdx;
|
use super::seg::SegIdx;
|
||||||
pub use super::seg::{DOWN_HEADER_SIZE, MAX_TOTAL_PACKET_SIZE, UP_HEADER_SIZE};
|
pub use super::seg::{DOWN_HEADER_SIZE, MAX_TOTAL_PACKET_SIZE, UP_HEADER_SIZE};
|
||||||
use byteorder::ByteOrder;
|
use byteorder::ByteOrder;
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum UpMsg {
|
pub enum UpMsg {
|
||||||
|
@ -14,7 +13,8 @@ pub enum UpMsg {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum DownMsg {
|
pub enum DownMsg {
|
||||||
Ack { idxs: HashSet<SegIdx> },
|
/// `idxs` must be distinct and in increasing order.
|
||||||
|
Ack { idxs: Vec<SegIdx> },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
@ -56,19 +56,29 @@ impl SerDes for UpMsg {
|
||||||
|
|
||||||
impl SerDes for DownMsg {
|
impl SerDes for DownMsg {
|
||||||
fn des(buf: &[u8]) -> Result<Self, DesError> {
|
fn des(buf: &[u8]) -> Result<Self, DesError> {
|
||||||
let mut idxs = HashSet::new();
|
let mut idxs = vec![];
|
||||||
for (i, b) in buf.iter().cloned().enumerate() {
|
for (i, b) in buf.iter().cloned().enumerate() {
|
||||||
for j in 0..8 {
|
for j in 0..8 {
|
||||||
if b & (1 << j) != 0 {
|
if b & (1 << j) != 0 {
|
||||||
idxs.insert((i * 8 + j) as SegIdx);
|
idxs.push((i * 8 + j) as SegIdx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(DownMsg::Ack { idxs })
|
Ok(DownMsg::Ack { idxs })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ser_to(&self, _buf: &mut [u8]) -> usize {
|
fn ser_to(&self, buf: &mut [u8]) -> usize {
|
||||||
// TODO: implement this!
|
match self {
|
||||||
0
|
DownMsg::Ack { idxs } => {
|
||||||
|
let mut max_i = 0;
|
||||||
|
for seg_idx in idxs.iter().cloned() {
|
||||||
|
let i = seg_idx as usize / 8;
|
||||||
|
let j = (seg_idx % 8) as u8;
|
||||||
|
buf[i] |= 1 << j;
|
||||||
|
max_i = std::cmp::max(i, max_i);
|
||||||
|
}
|
||||||
|
max_i + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue