123456789101112131415161718192021222324252627282930 |
- use std::io::Cursor;
- use binrw::{BinRead, BinWrite};
- use ezcad::types::U32;
- #[test]
- fn field_u32_be() {
- let encoded: Vec<u8> = vec![0x00, 0x00, 0x00, 0x04, 0x0A, 0x0B, 0x0C, 0x0D];
- let decoded: u32 = 0x0A0B0C0D;
- let mut stream: Cursor<Vec<u8>> = Cursor::new(encoded.clone());
- assert_eq!(U32::read_be(&mut stream).unwrap(), decoded.into());
- let mut buffer: Cursor<Vec<u8>> = Cursor::new(vec![]);
- U32::from(decoded).write_be(&mut buffer).unwrap();
- assert_eq!(buffer.into_inner(), encoded);
- }
- #[test]
- fn field_u32_le() {
- let encoded: Vec<u8> = vec![0x04, 0x00, 0x00, 0x00, 0x0D, 0x0C, 0x0B, 0x0A];
- let decoded: u32 = 0x0A0B0C0D;
- let mut stream: Cursor<Vec<u8>> = Cursor::new(encoded.clone());
- assert_eq!(U32::read_le(&mut stream).unwrap(), decoded.into());
- let mut buffer: Cursor<Vec<u8>> = Cursor::new(vec![]);
- U32::from(decoded).write_le(&mut buffer).unwrap();
- assert_eq!(buffer.into_inner(), encoded);
- }
|