1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Shared helpers for `QuantizationCodec` serialization and deserialization.
//!
//! RF-DEDUP: Both `QuantizedVector` (SQ8) and `BinaryQuantizedVector` share
//! the same serialization pattern: fixed-size header + opaque payload.
//! These helpers eliminate duplicated capacity pre-allocation, header
//! writing, minimum-length validation, and payload slicing logic.
use io;
/// Serializes a header and payload into a single byte buffer.
///
/// Pre-allocates exactly `header.len() + payload.len()` bytes, then
/// writes the header followed by the payload with zero reallocation.
///
/// # Examples (internal only)
///
/// ```ignore
/// let header = min.to_le_bytes().iter().chain(&max.to_le_bytes()).copied().collect::<Vec<u8>>();
/// let bytes = serialize_with_header(&header, &self.data);
/// ```
pub
/// Validates that `bytes` has at least `header_size` bytes and splits it
/// into `(header, payload)`.
///
/// Returns `Err(InvalidData)` when the input is shorter than the required
/// header, embedding `type_name` in the error message for diagnostics.
///
/// # Errors
///
/// Returns [`io::Error`] with kind [`io::ErrorKind::InvalidData`] when
/// `bytes.len() < header_size`.
pub