|
@@ -5,16 +5,15 @@ use ezcad::array_of::ArrayOf;
|
|
|
|
|
|
#[test]
|
|
|
fn array_of_be() {
|
|
|
- let encoded: Vec<u8> = vec![0x00, 0x00, 0x00, 0x02, 0x0A, 0x0B, 0x0C, 0x0D, 0x01, 0x02, 0x03, 0x04];
|
|
|
+ let encoded: Vec<u8> = vec![
|
|
|
+ 0x00, 0x00, 0x00, 0x02, 0x0A, 0x0B, 0x0C, 0x0D, 0x01, 0x02, 0x03, 0x04,
|
|
|
+ ];
|
|
|
let decoded: ArrayOf<u32> = ArrayOf {
|
|
|
- value: vec![0x0A0B0C0D, 0x01020304]
|
|
|
+ value: vec![0x0A0B0C0D, 0x01020304],
|
|
|
};
|
|
|
|
|
|
let mut stream: Cursor<Vec<u8>> = Cursor::new(encoded.clone());
|
|
|
- assert_eq!(
|
|
|
- ArrayOf::<u32>::read_be(&mut stream).unwrap(),
|
|
|
- decoded
|
|
|
- );
|
|
|
+ assert_eq!(ArrayOf::<u32>::read_be(&mut stream).unwrap(), decoded);
|
|
|
|
|
|
let mut buffer: Cursor<Vec<u8>> = Cursor::new(vec![]);
|
|
|
decoded.write_be(&mut buffer).unwrap();
|
|
@@ -23,18 +22,49 @@ fn array_of_be() {
|
|
|
|
|
|
#[test]
|
|
|
fn array_of_le() {
|
|
|
- let encoded: Vec<u8> = vec![0x02, 0x00, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x01, 0x02, 0x03, 0x04];
|
|
|
+ let encoded: Vec<u8> = vec![
|
|
|
+ 0x02, 0x00, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x01, 0x02, 0x03, 0x04,
|
|
|
+ ];
|
|
|
let decoded: ArrayOf<u32> = ArrayOf {
|
|
|
- value: vec![0x0D0C0B0A, 0x04030201]
|
|
|
+ value: vec![0x0D0C0B0A, 0x04030201],
|
|
|
};
|
|
|
|
|
|
let mut stream: Cursor<Vec<u8>> = Cursor::new(encoded.clone());
|
|
|
- assert_eq!(
|
|
|
- ArrayOf::<u32>::read_le(&mut stream).unwrap(),
|
|
|
- decoded
|
|
|
- );
|
|
|
+ assert_eq!(ArrayOf::<u32>::read_le(&mut stream).unwrap(), decoded);
|
|
|
|
|
|
let mut buffer: Cursor<Vec<u8>> = Cursor::new(vec![]);
|
|
|
decoded.write_le(&mut buffer).unwrap();
|
|
|
assert_eq!(buffer.into_inner(), encoded);
|
|
|
}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn array_of_struct() {
|
|
|
+ #[derive(BinRead, BinWrite, Debug, PartialEq, Default)]
|
|
|
+ struct Test {
|
|
|
+ a: u16,
|
|
|
+ b: u16,
|
|
|
+ }
|
|
|
+
|
|
|
+ let encoded: Vec<u8> = vec![
|
|
|
+ 0x00, 0x00, 0x00, 0x02, 0x0A, 0x0B, 0x0C, 0x0D, 0x01, 0x02, 0x03, 0x04,
|
|
|
+ ];
|
|
|
+ let decoded: ArrayOf<Test> = ArrayOf {
|
|
|
+ value: vec![
|
|
|
+ Test {
|
|
|
+ a: 0x0A0B,
|
|
|
+ b: 0x0C0D,
|
|
|
+ },
|
|
|
+ Test {
|
|
|
+ a: 0x0102,
|
|
|
+ b: 0x0304,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ };
|
|
|
+
|
|
|
+ let mut stream: Cursor<Vec<u8>> = Cursor::new(encoded.clone());
|
|
|
+ assert_eq!(ArrayOf::<Test>::read_be(&mut stream).unwrap(), decoded);
|
|
|
+
|
|
|
+ let mut buffer: Cursor<Vec<u8>> = Cursor::new(vec![]);
|
|
|
+ decoded.write_be(&mut buffer).unwrap();
|
|
|
+ assert_eq!(buffer.into_inner(), encoded);
|
|
|
+}
|