MCPcopy Create free account
hub / github.com/Ray-D-Song/lexe / endian_bytes

Function endian_bytes

modules/llrt_buffer/src/buffer.rs:574–590  ·  view source on GitHub ↗

Pure mathematical byte generation

(mut val: u64, endian: Endian)

Source from the content-addressed store, hash-verified

572
573// Pure mathematical byte generation
574fn endian_bytes(mut val: u64, endian: Endian) -> Vec<u8> {
575 let mut bytes = vec![0u8; 8];
576
577 #[allow(clippy::needless_range_loop)]
578 for i in 0..8 {
579 bytes[i] = match endian {
580 Endian::Big => (val >> (56 - i * 8)) as u8,
581 Endian::Little => (val >> (i * 8)) as u8,
582 };
583 // Clear processed bits
584 match endian {
585 Endian::Big => val &= !(0xFF << ((7 - i) * 8)),
586 Endian::Little => val &= !(0xFF << (i * 8)),
587 }
588 }
589 bytes
590}
591
592fn shifted_bytes(mut val: u64, bits: u8, endian: Endian) -> Vec<u8> {
593 let byte_count = (bits / 8) as usize;

Callers 1

write_bufFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected