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

Function test_codec_8bytes_primitives

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

Source from the content-addressed store, hash-verified

499
500 #[test]
501 fn test_codec_8bytes_primitives() {
502 #[derive(Debug, PartialEq, Eq, PackedSize, EncodeLE, DecodeLE, EncodeBE, DecodeBE)]
503 struct A {
504 a: u64,
505 b: i64,
506 }
507
508 let test = A {
509 a: 0x2F,
510 b: 0x2F000000_00000000,
511 };
512 assert_eq!(A::PACKED_LEN, 16);
513 let mut bytes = [0; A::PACKED_LEN];
514
515 // LE
516 let size = test.encode_as_le_bytes(&mut bytes);
517 assert_eq!([47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47], bytes);
518 assert_eq!(A::PACKED_LEN, size);
519
520 let test_back = A::decode_from_le_bytes(&bytes);
521 assert_eq!(test, test_back);
522
523 //BE
524 let size = test.encode_as_be_bytes(&mut bytes);
525 assert_eq!([0, 0, 0, 0, 0, 0, 0, 47, 47, 0, 0, 0, 0, 0, 0, 0,], bytes);
526 assert_eq!(A::PACKED_LEN, size);
527
528 let test_back = A::decode_from_be_bytes(&bytes);
529 assert_eq!(test, test_back);
530 }
531
532 #[test]
533 fn test_codec_16bytes_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