From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- third_party/rust/scroll_derive/examples/main.rs | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 third_party/rust/scroll_derive/examples/main.rs (limited to 'third_party/rust/scroll_derive/examples/main.rs') diff --git a/third_party/rust/scroll_derive/examples/main.rs b/third_party/rust/scroll_derive/examples/main.rs new file mode 100644 index 0000000000..faec85300b --- /dev/null +++ b/third_party/rust/scroll_derive/examples/main.rs @@ -0,0 +1,28 @@ +use scroll_derive::{IOread, IOwrite, Pread, Pwrite, SizeWith}; + +#[derive(Debug, PartialEq, Pread, Pwrite, IOread, IOwrite, SizeWith)] +#[repr(C)] +struct Data { + id: u32, + timestamp: f64, + arr: [u16; 2], +} + +use scroll::{Cread, Pread, Pwrite, LE}; + +fn main() { + let bytes = [ + 0xefu8, 0xbe, 0xad, 0xde, 0, 0, 0, 0, 0, 0, 224, 63, 0xad, 0xde, 0xef, 0xbe, + ]; + let data: Data = bytes.pread_with(0, LE).unwrap(); + println!("data: {:?}", &data); + assert_eq!(data.id, 0xdeadbeefu32); + let mut bytes2 = vec![0; ::std::mem::size_of::()]; + bytes2.pwrite_with(data, 0, LE).unwrap(); + let data: Data = bytes.pread_with(0, LE).unwrap(); + let data2: Data = bytes2.pread_with(0, LE).unwrap(); + assert_eq!(data, data2); + + let data: Data = bytes.cread_with(0, LE); + assert_eq!(data, data2); +} -- cgit v1.2.3