MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / to_bytes

Method to_bytes

nodedb-vector/src/quantize/pq.rs:210–221  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 ///

Callers 3

checkpoint_to_bytesMethod · 0.45
pq_codec_golden_formatFunction · 0.45

Calls 3

try_reserve_or_skipFunction · 0.85
lenMethod · 0.45
pushMethod · 0.45

Tested by 2

pq_codec_golden_formatFunction · 0.36