MCPcopy Create free account
hub / github.com/Slowerzs/PPLSystem / test_codec_array

Function test_codec_array

endian_codec/src/lib.rs:616–644  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

614
615 #[test]
616 fn test_codec_array() {
617 type A = [u16; 8];
618
619 let mut i = 0;
620 let test: A = [(); 8].map(|_| {
621 let ret = i as u16;
622 i += 1;
623 ret
624 });
625
626 assert_eq!(A::PACKED_LEN, 16);
627 let mut bytes = [0; A::PACKED_LEN];
628
629 //LE
630 let size = test.encode_as_le_bytes(&mut bytes);
631 assert_eq!([0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0], bytes);
632 assert_eq!(A::PACKED_LEN, size);
633
634 let test_back = A::decode_from_le_bytes(&bytes);
635 assert_eq!(test, test_back);
636
637 //BE
638 let size = test.encode_as_be_bytes(&mut bytes);
639 assert_eq!([0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7], bytes);
640 assert_eq!(A::PACKED_LEN, size);
641
642 let test_back = A::decode_from_be_bytes(&bytes);
643 assert_eq!(test, test_back);
644 }
645
646 /*
647 This will not compile because EncodeME derive require A to implement EncodeME.

Callers

nothing calls this directly

Calls 2

encode_as_le_bytesMethod · 0.80
encode_as_be_bytesMethod · 0.80

Tested by

no test coverage detected