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

Function test_codec_4bytes_primitives

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

Source from the content-addressed store, hash-verified

467
468 #[test]
469 fn test_codec_4bytes_primitives() {
470 #[derive(Debug, PartialEq, Eq, PackedSize, EncodeLE, DecodeLE, EncodeBE, DecodeBE)]
471 struct A {
472 a: u32,
473 b: i32,
474 }
475
476 let test = A {
477 a: 0x2F,
478 b: 0x2F000000,
479 };
480 assert_eq!(A::PACKED_LEN, 8);
481 let mut bytes = [0; A::PACKED_LEN];
482
483 // LE
484 let size = test.encode_as_le_bytes(&mut bytes);
485 assert_eq!([47, 0, 0, 0, 0, 0, 0, 47], bytes);
486 assert_eq!(A::PACKED_LEN, size);
487
488 let test_back = A::decode_from_le_bytes(&bytes);
489 assert_eq!(test, test_back);
490
491 //BE
492 let size = test.encode_as_be_bytes(&mut bytes);
493 assert_eq!([0, 0, 0, 47, 47, 0, 0, 0], bytes);
494 assert_eq!(A::PACKED_LEN, size);
495
496 let test_back = A::decode_from_be_bytes(&bytes);
497 assert_eq!(test, test_back);
498 }
499
500 #[test]
501 fn test_codec_8bytes_primitives() {

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