-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
588 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::encode::Encode; | ||
use crate::point; | ||
use crate::point::Point; | ||
use crate::util::bool32; | ||
use nom::combinator::map; | ||
use nom::multi::length_count; | ||
use nom::number::complete::le_u32; | ||
use nom::sequence::tuple; | ||
use nom::IResult; | ||
|
||
#[derive(Debug)] | ||
pub struct AlignmentData { | ||
pub needed: bool, | ||
pub marks: Vec<Point>, | ||
} | ||
|
||
pub(crate) fn read_alignment_data(input: &[u8]) -> IResult<&[u8], AlignmentData> { | ||
map( | ||
tuple((bool32, length_count(le_u32, point::read_point))), | ||
|(needed, marks)| AlignmentData { needed, marks }, | ||
)(input) | ||
} | ||
|
||
impl Encode for AlignmentData { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> std::io::Result<()> { | ||
(self.needed as u32).encode(buffer)?; | ||
(self.marks.len() as u32).encode(buffer)?; | ||
for mark in &self.marks { | ||
mark.encode(buffer)?; | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use std::io; | ||
use std::io::Write; | ||
|
||
pub(crate) trait Encode { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()>; | ||
|
||
fn encode_to_vec(&self) -> io::Result<Vec<u8>> { | ||
let mut buffer = Vec::new(); | ||
self.encode(&mut buffer)?; | ||
Ok(buffer) | ||
} | ||
} | ||
|
||
impl Encode for u8 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Encode for u16 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Encode for u32 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Encode for u64 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Encode for u128 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Encode for i8 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Encode for i16 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Encode for i32 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Encode for i64 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Encode for i128 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Encode for f32 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Encode for f64 { | ||
fn encode(&self, buffer: &mut Vec<u8>) -> io::Result<()> { | ||
buffer.write(&self.to_le_bytes())?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.