12345678910111213141516171819202122232425262728293031323334353637383940 |
- use std::io::Cursor;
- use binrw::{BinRead, BinWrite};
- use ezcad::basic_field::BasicField;
- #[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!(
- BasicField::read_be(&mut stream).unwrap(),
- BasicField::U32(decoded.into())
- );
- let mut buffer: Cursor<Vec<u8>> = Cursor::new(vec![]);
- BasicField::U32(decoded.into())
- .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!(
- BasicField::read_le(&mut stream).unwrap(),
- BasicField::U32(decoded.into())
- );
- let mut buffer: Cursor<Vec<u8>> = Cursor::new(vec![]);
- BasicField::U32(decoded.into())
- .write_le(&mut buffer)
- .unwrap();
- assert_eq!(buffer.into_inner(), encoded);
- }
|