-
Notifications
You must be signed in to change notification settings - Fork 13
143 binrw structs ut refactor macros #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e1bc912
WIP: Migrate smb-msg decode_content to test_response_read! macro
afiffon 8cb2034
Add server/client/both features
afiffon 82f95a4
Add macros to req|resXread|write|both
afiffon a29857b
WIP: migrate encode_content and others to macros in smb-msg
afiffon 2914181
Random improvements:
afiffon aff650e
compressed tests migration
afiffon 68ef919
- Create contexts tests & bits of doc
afiffon 6cf99cc
wip: smb-msg tests
afiffon decc012
Get rid of header bytes from smb-msg tests
afiffon bff7a98
Eliminate ALL test Cursor usages
afiffon 36c95cb
- get rid of more manual writing in smb-dtyp leftovers
afiffon 8714b82
build bugfix
afiffon 89f5cf1
CR Fixes:
afiffon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,74 @@ | ||
| //! [`Boolean`][crate::Boolean] implementation for binrw. | ||
|
|
||
| use binrw::{Endian, prelude::*}; | ||
| use std::io::{Read, Seek, Write}; | ||
|
|
||
| /// A simple Boolean type that reads and writes as a single byte. | ||
| /// Any non-zero value is considered `true`, as defined by MS-FSCC 2.1.8. | ||
| /// Similar to the WinAPI `BOOL` type. | ||
| /// | ||
| /// This type supports `std::size_of::<Boolean>() == 1`, ensuring it is 1 byte in size. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub struct Boolean(bool); | ||
|
|
||
| impl Boolean { | ||
| const _VALIDATE_SIZE_OF: [u8; 1] = [0; size_of::<Self>()]; | ||
| } | ||
|
|
||
| impl BinRead for Boolean { | ||
| type Args<'a> = (); | ||
|
|
||
| fn read_options<R: Read + Seek>( | ||
| reader: &mut R, | ||
| _: Endian, | ||
| _: Self::Args<'_>, | ||
| ) -> binrw::BinResult<Self> { | ||
| let value: u8 = u8::read_options(reader, Endian::Little, ())?; | ||
| Ok(Boolean(value != 0)) | ||
| } | ||
| } | ||
|
|
||
| impl BinWrite for Boolean { | ||
| type Args<'a> = (); | ||
|
|
||
| fn write_options<W: Write + Seek>( | ||
| &self, | ||
| writer: &mut W, | ||
| _: Endian, | ||
| _: Self::Args<'_>, | ||
| ) -> binrw::BinResult<()> { | ||
| let value: u8 = if self.0 { 1 } else { 0 }; | ||
| value.write_options(writer, Endian::Little, ()) | ||
| } | ||
| } | ||
|
|
||
| impl From<bool> for Boolean { | ||
| fn from(value: bool) -> Self { | ||
| Boolean(value) | ||
| } | ||
| } | ||
|
|
||
| impl From<Boolean> for bool { | ||
| fn from(val: Boolean) -> Self { | ||
| val.0 | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use smb_tests::*; | ||
|
|
||
| test_binrw! { | ||
| Boolean => true: Boolean::from(true) => "01" | ||
| } | ||
|
|
||
| test_binrw! { | ||
| Boolean => false: Boolean::from(false) => "00" | ||
| } | ||
|
|
||
| // Non-zero is considered true! | ||
| test_binrw_read! { | ||
| Boolean => true_non_zero: Boolean::from(true) => "17" | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.