add prefix / suffix to field
This commit is contained in:
parent
33e770e04a
commit
5dd96fb173
4 changed files with 176 additions and 22 deletions
3
androscalpel_serializer/src/constant.rs
Normal file
3
androscalpel_serializer/src/constant.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
//! Constants definition
|
||||
|
||||
pub use androscalpel_serializer_derive::*;
|
||||
|
|
@ -5,7 +5,7 @@ use std::io::{Cursor, Read, Seek, SeekFrom, Write};
|
|||
|
||||
pub use androscalpel_serializer_derive::*;
|
||||
|
||||
mod leb;
|
||||
pub mod leb;
|
||||
pub use leb::*;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
|
|
@ -849,4 +849,29 @@ mod test {
|
|||
);
|
||||
assert!(TestEnum::deserialize_from_slice(&[255u8]).is_err());
|
||||
}
|
||||
|
||||
#[derive(Serializable, PartialEq, Debug)]
|
||||
struct TestPrefixSuffix {
|
||||
#[prefix([0x42])]
|
||||
#[suffix([0x66, 0x66])]
|
||||
a: u32,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_prefix_suffix() {
|
||||
assert_eq!(
|
||||
TestPrefixSuffix::deserialize_from_slice(&[0x42, 0, 1, 2, 3, 0x66, 0x66]).unwrap(),
|
||||
TestPrefixSuffix { a: 0x00010203 }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_prefix_suffix() {
|
||||
assert_eq!(
|
||||
TestPrefixSuffix { a: 0x00010203 }
|
||||
.serialize_to_vec()
|
||||
.unwrap(),
|
||||
vec![0x42, 0, 1, 2, 3, 0x66, 0x66]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
pub mod constant;
|
||||
pub mod core;
|
||||
|
||||
pub use crate::core::*;
|
||||
pub use constant::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue