()
| 575 | |
| 576 | #[test] |
| 577 | fn test_codec_nested() { |
| 578 | #[derive(Debug, PartialEq, Eq, PackedSize, EncodeLE, DecodeLE, EncodeBE, DecodeBE)] |
| 579 | struct A { |
| 580 | a: u32, |
| 581 | b: u8, |
| 582 | } |
| 583 | |
| 584 | #[derive(Debug, PartialEq, Eq, PackedSize, EncodeLE, DecodeLE, EncodeBE, DecodeBE)] |
| 585 | struct B { |
| 586 | a: A, |
| 587 | b: u16, |
| 588 | } |
| 589 | |
| 590 | let test = B { |
| 591 | a: A { a: 0x2F, b: 0x88 }, |
| 592 | b: 0x55, |
| 593 | }; |
| 594 | |
| 595 | assert_eq!(B::PACKED_LEN, 7); |
| 596 | let mut bytes = [0; B::PACKED_LEN]; |
| 597 | |
| 598 | // LE |
| 599 | let size = test.encode_as_le_bytes(&mut bytes); |
| 600 | assert_eq!([0x2f, 0, 0, 0, 0x88, 0x55, 0], bytes); |
| 601 | assert_eq!(B::PACKED_LEN, size); |
| 602 | |
| 603 | let test_back = B::decode_from_le_bytes(&bytes); |
| 604 | assert_eq!(test, test_back); |
| 605 | |
| 606 | //BE |
| 607 | let size = test.encode_as_be_bytes(&mut bytes); |
| 608 | assert_eq!([0, 0, 0, 0x2f, 0x88, 0, 0x55], bytes); |
| 609 | assert_eq!(B::PACKED_LEN, size); |
| 610 | |
| 611 | let test_back = B::decode_from_be_bytes(&bytes); |
| 612 | assert_eq!(test, test_back); |
| 613 | } |
| 614 | |
| 615 | #[test] |
| 616 | fn test_codec_array() { |
nothing calls this directly
no test coverage detected