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

Function encode

nodedb-codec/src/vector_quant/codec_envelope.rs:21–34  ·  view source on GitHub ↗

Serialize `value` into a versioned, magic-tagged byte buffer.

(
    magic: &[u8; MAGIC_LEN],
    version: u8,
    value: &T,
)

Source from the content-addressed store, hash-verified

19
20/// Serialize `value` into a versioned, magic-tagged byte buffer.
21pub fn encode<T: ToMessagePack>(
22 magic: &[u8; MAGIC_LEN],
23 version: u8,
24 value: &T,
25) -> Result<Vec<u8>, CodecError> {
26 let body = zerompk::to_msgpack_vec(value).map_err(|e| CodecError::Corrupt {
27 detail: e.to_string(),
28 })?;
29 let mut out = Vec::with_capacity(HEADER_LEN + body.len());
30 out.extend_from_slice(magic);
31 out.push(version);
32 out.extend_from_slice(&body);
33 Ok(out)
34}
35
36/// Validate the envelope header and deserialize the body into `T`.
37///

Callers 6

to_bytesMethod · 0.70
to_bytesMethod · 0.70
roundtripFunction · 0.70
rejects_bad_magicFunction · 0.70
rejects_version_mismatchFunction · 0.70

Calls 3

to_stringMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45

Tested by 4

roundtripFunction · 0.56
rejects_bad_magicFunction · 0.56
rejects_version_mismatchFunction · 0.56