Skip to content

Commit

Permalink
fix event order
Browse files Browse the repository at this point in the history
  • Loading branch information
hohav committed Sep 30, 2023
1 parent a999ba3 commit 53254d6
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 12 deletions.
59 changes: 53 additions & 6 deletions gen/resources/preamble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Data {
}
}

pub fn write<W: Write>(
pub fn write_pre<W: Write>(
&self,
w: &mut W,
version: Version,
Expand All @@ -79,7 +79,17 @@ impl Data {
_ => 0,
})?;
self.pre.write(w, version, idx)?;
Ok(())
}

pub fn write_post<W: Write>(
&self,
w: &mut W,
version: Version,
idx: usize,
frame_id: i32,
port: PortOccupancy,
) -> Result<()> {
w.write_u8(0x38)?; // FIXME: don't hard-code
w.write_i32::<BE>(frame_id)?;
w.write_u8(port.port as u8)?;
Expand All @@ -88,7 +98,6 @@ impl Data {
_ => 0,
})?;
self.post.write(w, version, idx)?;

Ok(())
}
}
Expand Down Expand Up @@ -168,14 +177,48 @@ impl PortData {
}
}

pub fn write<W: Write>(
pub fn write_pre<W: Write>(
&self,
w: &mut W,
version: Version,
idx: usize,
frame_id: i32,
) -> Result<()> {
self.leader.write_pre(
w,
version,
idx,
frame_id,
PortOccupancy {
port: self.port,
follower: false,
},
)?;
self.follower
.as_ref()
.map(|f| {
f.write_pre(
w,
version,
idx,
frame_id,
PortOccupancy {
port: self.port,
follower: false,
},
)
})
.unwrap_or(Ok(()))
}

pub fn write_post<W: Write>(
&self,
w: &mut W,
version: Version,
idx: usize,
frame_id: i32,
) -> Result<()> {
self.leader.write(
self.leader.write_post(
w,
version,
idx,
Expand All @@ -188,7 +231,7 @@ impl PortData {
self.follower
.as_ref()
.map(|f| {
f.write(
f.write_post(
w,
version,
idx,
Expand All @@ -201,6 +244,7 @@ impl PortData {
})
.unwrap_or(Ok(()))
}

}

pub struct MutablePortData {
Expand Down Expand Up @@ -377,13 +421,16 @@ impl Frame {
self.start.write(w, version, idx)?;
}
for port in &self.port {
port.write(w, version, idx, frame_id)?;
port.write_pre(w, version, idx, frame_id)?;
}
for item_idx in self.item_offset[idx] as usize..self.item_offset[idx + 1] as usize {
w.write_u8(0x3B)?;
w.write_i32::<BE>(frame_id)?;
self.item.write(w, version, item_idx)?;
}
for port in &self.port {
port.write_post(w, version, idx, frame_id)?;
}
if version > Version(3, 0, 0) {
w.write_u8(0x3C)?;
w.write_i32::<BE>(frame_id)?;
Expand Down
58 changes: 52 additions & 6 deletions src/model/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Data {
}
}

pub fn write<W: Write>(
pub fn write_pre<W: Write>(
&self,
w: &mut W,
version: Version,
Expand All @@ -81,7 +81,17 @@ impl Data {
_ => 0,
})?;
self.pre.write(w, version, idx)?;
Ok(())
}

pub fn write_post<W: Write>(
&self,
w: &mut W,
version: Version,
idx: usize,
frame_id: i32,
port: PortOccupancy,
) -> Result<()> {
w.write_u8(0x38)?; // FIXME: don't hard-code
w.write_i32::<BE>(frame_id)?;
w.write_u8(port.port as u8)?;
Expand All @@ -90,7 +100,6 @@ impl Data {
_ => 0,
})?;
self.post.write(w, version, idx)?;

Ok(())
}
}
Expand Down Expand Up @@ -170,14 +179,14 @@ impl PortData {
}
}

pub fn write<W: Write>(
pub fn write_pre<W: Write>(
&self,
w: &mut W,
version: Version,
idx: usize,
frame_id: i32,
) -> Result<()> {
self.leader.write(
self.leader.write_pre(
w,
version,
idx,
Expand All @@ -190,7 +199,41 @@ impl PortData {
self.follower
.as_ref()
.map(|f| {
f.write(
f.write_pre(
w,
version,
idx,
frame_id,
PortOccupancy {
port: self.port,
follower: false,
},
)
})
.unwrap_or(Ok(()))
}

pub fn write_post<W: Write>(
&self,
w: &mut W,
version: Version,
idx: usize,
frame_id: i32,
) -> Result<()> {
self.leader.write_post(
w,
version,
idx,
frame_id,
PortOccupancy {
port: self.port,
follower: false,
},
)?;
self.follower
.as_ref()
.map(|f| {
f.write_post(
w,
version,
idx,
Expand Down Expand Up @@ -379,13 +422,16 @@ impl Frame {
self.start.write(w, version, idx)?;
}
for port in &self.port {
port.write(w, version, idx, frame_id)?;
port.write_pre(w, version, idx, frame_id)?;
}
for item_idx in self.item_offset[idx] as usize..self.item_offset[idx + 1] as usize {
w.write_u8(0x3B)?;
w.write_i32::<BE>(frame_id)?;
self.item.write(w, version, item_idx)?;
}
for port in &self.port {
port.write_post(w, version, idx, frame_id)?;
}
if version > Version(3, 0, 0) {
w.write_u8(0x3C)?;
w.write_i32::<BE>(frame_id)?;
Expand Down

0 comments on commit 53254d6

Please sign in to comment.