(out: &mut [u8], val: Option<&[u8]>, opts: SortOptions)
| 161 | |
| 162 | #[inline] |
| 163 | pub fn encode_one(out: &mut [u8], val: Option<&[u8]>, opts: SortOptions) -> usize { |
| 164 | match val { |
| 165 | None => encode_null(out, opts), |
| 166 | Some([]) => encode_empty(out, opts), |
| 167 | Some(val) => { |
| 168 | // Write `2_u8` to demarcate as non-empty, non-null string |
| 169 | out[0] = NON_EMPTY_SENTINEL; |
| 170 | |
| 171 | let len = if val.len() <= BLOCK_SIZE { |
| 172 | 1 + encode_blocks::<MINI_BLOCK_SIZE>(&mut out[1..], val) |
| 173 | } else { |
| 174 | let (initial, rem) = val.split_at(BLOCK_SIZE); |
| 175 | let offset = encode_blocks::<MINI_BLOCK_SIZE>(&mut out[1..], initial); |
| 176 | out[offset] = BLOCK_CONTINUATION; |
| 177 | 1 + offset + encode_blocks::<BLOCK_SIZE>(&mut out[1 + offset..], rem) |
| 178 | }; |
| 179 | |
| 180 | if opts.descending { |
| 181 | // Invert bits |
| 182 | out[..len].iter_mut().for_each(|v| *v = !*v) |
| 183 | } |
| 184 | len |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /// Writes `val` in `SIZE` blocks with the appropriate continuation tokens |
| 190 | #[inline] |
no test coverage detected