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

Function test_codec_2bytes_primitives

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

Source from the content-addressed store, hash-verified

438
439 #[test]
440 fn test_codec_2bytes_primitives() {
441 #[derive(Debug, PartialEq, Eq, PackedSize, EncodeLE, DecodeLE, EncodeBE, DecodeBE)]
442 struct A {
443 a: u16,
444 b: i16,
445 }
446
447 let test = A { a: 0x2F, b: 0x2F00 };
448 assert_eq!(A::PACKED_LEN, 4);
449 let mut bytes = [0; A::PACKED_LEN];
450
451 // LE
452 let size = test.encode_as_le_bytes(&mut bytes);
453 assert_eq!([47, 0, 0, 47], bytes);
454 assert_eq!(A::PACKED_LEN, size);
455
456 let test_back = A::decode_from_le_bytes(&bytes);
457 assert_eq!(test, test_back);
458
459 //BE
460 let size = test.encode_as_be_bytes(&mut bytes);
461 assert_eq!([0, 47, 47, 0], bytes);
462 assert_eq!(A::PACKED_LEN, size);
463
464 let test_back = A::decode_from_be_bytes(&bytes);
465 assert_eq!(test, test_back);
466 }
467
468 #[test]
469 fn test_codec_4bytes_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