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

Function test_codec_nested

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

Source from the content-addressed store, hash-verified

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() {

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