-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add read_all attribute to read until the reader.end() returns true
- Loading branch information
1 parent
7176d1b
commit 6ce37c6
Showing
12 changed files
with
270 additions
and
1 deletion.
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
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,23 @@ | ||
use deku::prelude::*; | ||
use std::convert::{TryFrom, TryInto}; | ||
|
||
fn main() { | ||
#[derive(PartialEq, Debug, DekuRead, DekuWrite)] | ||
struct TestStruct { | ||
#[deku(read_all)] | ||
data: Vec<(u8, u8)>, | ||
} | ||
|
||
let test_data: Vec<u8> = [0xaa, 0xbb, 0xcc, 0xdd].to_vec(); | ||
|
||
let ret_read = TestStruct::try_from(test_data.as_slice()).unwrap(); | ||
assert_eq!( | ||
TestStruct { | ||
data: vec![(0xaa, 0xbb), (0xcc, 0xdd)] | ||
}, | ||
ret_read | ||
); | ||
|
||
let ret_write: Vec<u8> = ret_read.try_into().unwrap(); | ||
assert_eq!(test_data, ret_write); | ||
} |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod test_bits_read; | ||
mod test_bytes_read; | ||
mod test_count; | ||
mod test_read_all; | ||
mod test_until; |
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,46 @@ | ||
use std::convert::{TryFrom, TryInto}; | ||
|
||
use deku::prelude::*; | ||
|
||
#[test] | ||
fn test_read_all() { | ||
#[derive(PartialEq, Debug, DekuRead, DekuWrite)] | ||
struct TestStruct1 { | ||
#[deku(read_all)] | ||
data: Vec<u8>, | ||
} | ||
|
||
let test_data: Vec<u8> = [0xaa, 0xbb].to_vec(); | ||
|
||
let ret_read = TestStruct1::try_from(test_data.as_slice()).unwrap(); | ||
assert_eq!( | ||
TestStruct1 { | ||
data: test_data.to_vec() | ||
}, | ||
ret_read | ||
); | ||
|
||
let ret_write: Vec<u8> = ret_read.try_into().unwrap(); | ||
assert_eq!(test_data, ret_write); | ||
|
||
#[derive(PartialEq, Debug, DekuRead, DekuWrite)] | ||
struct TestStruct2 { | ||
first: u8, | ||
#[deku(read_all)] | ||
data: Vec<u8>, | ||
} | ||
|
||
let test_data: Vec<u8> = [0xff, 0xaa, 0xbb].to_vec(); | ||
|
||
let ret_read = TestStruct2::try_from(test_data.as_slice()).unwrap(); | ||
assert_eq!( | ||
TestStruct2 { | ||
first: 0xff, | ||
data: test_data[1..].to_vec() | ||
}, | ||
ret_read | ||
); | ||
|
||
let ret_write: Vec<u8> = ret_read.try_into().unwrap(); | ||
assert_eq!(test_data, ret_write); | ||
} |
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.