Serialize the codec to bytes with a versioned magic header. Format: `[NDPQ\0\0 (6 bytes)][version: u8 = 1][msgpack payload]` Charges the estimated serialized size to the governor (if set) before allocating the output buffer. The estimate is conservative: `m * k * sub_dim * size_of:: () + 64` (header + framing overhead).
(&self)
| 208 | /// allocating the output buffer. The estimate is conservative: |
| 209 | /// `m * k * sub_dim * size_of::<f32>() + 64` (header + framing overhead). |
| 210 | pub fn to_bytes(&self) -> Result<Vec<u8>, VectorError> { |
| 211 | const MAGIC: &[u8; 6] = b"NDPQ\0\0"; |
| 212 | const VERSION: u8 = 1; |
| 213 | let estimated = self.m * self.k * self.sub_dim * size_of::<f32>() + 64; |
| 214 | let _g = try_reserve_or_skip(&self.governor, estimated)?; |
| 215 | let payload = zerompk::to_msgpack_vec(self).unwrap_or_default(); |
| 216 | let mut out = Vec::with_capacity(7 + payload.len()); |
| 217 | out.extend_from_slice(MAGIC); |
| 218 | out.push(VERSION); |
| 219 | out.extend_from_slice(&payload); |
| 220 | Ok(out) |
| 221 | } |
| 222 | |
| 223 | /// Deserialize the codec from bytes produced by [`Self::to_bytes`]. |
| 224 | /// |