MCPcopy Create free account
hub / github.com/SoftbearStudios/bitcode / pack_bytes_unsigned

Function pack_bytes_unsigned

src/pack.rs:112–141  ·  view source on GitHub ↗

[`pack_bytes`] but after i8s have been cast to u8s.

(
    bytes: &mut [u8],
    out: &mut Vec<u8>,
    basic_packing: Packing,
    min: u8,
    max: u8,
)

Source from the content-addressed store, hash-verified

110
111/// [`pack_bytes`] but after i8s have been cast to u8s.
112fn pack_bytes_unsigned(
113 bytes: &mut [u8],
114 out: &mut Vec<u8>,
115 basic_packing: Packing,
116 min: u8,
117 max: u8,
118) {
119 // If subtracting min from all bytes results in a better packing do it, otherwise don't bother.
120 let offset_packing = Packing::new(max.wrapping_sub(min));
121 let p = if offset_packing > basic_packing && bytes.len() > 5 {
122 for b in bytes.iter_mut() {
123 *b = b.wrapping_sub(min);
124 }
125 offset_packing.write(out, true);
126 out.push(min);
127 offset_packing
128 } else {
129 basic_packing.write(out, false);
130 basic_packing
131 };
132
133 match p {
134 Packing::_256 => out.extend_from_slice(bytes),
135 Packing::_16 => pack_arithmetic::<16>(bytes, out),
136 Packing::_6 => pack_arithmetic::<6>(bytes, out),
137 Packing::_4 => pack_arithmetic::<4>(bytes, out),
138 Packing::_3 => pack_arithmetic::<3>(bytes, out),
139 Packing::_2 => pack_arithmetic::<2>(bytes, out),
140 }
141}
142
143/// Opposite of `pack_bytes`. Needs to know the `length` in bytes. `out` is overwritten with the bytes.
144pub fn unpack_bytes<'a, T: Byte>(

Callers 1

pack_bytesFunction · 0.85

Calls 2

lenMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected