(&mut self, xor: u64)
| 101 | } |
| 102 | |
| 103 | fn encode_value_xor(&mut self, xor: u64) { |
| 104 | if xor == 0 { |
| 105 | self.buf.write_bit(false); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | self.buf.write_bit(true); |
| 110 | |
| 111 | let leading = xor.leading_zeros() as u8; |
| 112 | let trailing = xor.trailing_zeros() as u8; |
| 113 | |
| 114 | if self.prev_leading != u8::MAX |
| 115 | && leading >= self.prev_leading |
| 116 | && trailing >= self.prev_trailing |
| 117 | { |
| 118 | // Fits within previous window. |
| 119 | self.buf.write_bit(false); |
| 120 | let meaningful_bits = 64 - self.prev_leading - self.prev_trailing; |
| 121 | self.buf |
| 122 | .write_bits(xor >> self.prev_trailing, meaningful_bits as usize); |
| 123 | } else { |
| 124 | // New window. |
| 125 | self.buf.write_bit(true); |
| 126 | self.buf.write_bits(leading as u64, 6); |
| 127 | let meaningful_bits = 64 - leading - trailing; |
| 128 | self.buf.write_bits((meaningful_bits - 1) as u64, 6); |
| 129 | self.buf |
| 130 | .write_bits(xor >> trailing, meaningful_bits as usize); |
| 131 | self.prev_leading = leading; |
| 132 | self.prev_trailing = trailing; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /// Finish encoding and return compressed bytes. |
| 137 | /// |
no test coverage detected