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

Function encode_serde

nodedb/src/data/executor/response_codec/encode.rs:31–38  ·  view source on GitHub ↗

Encode any `Serialize` type as MessagePack bytes. Serializes via serde to an intermediate `serde_json::Value`, then converts to MessagePack. Use `encode()` for types that implement `ToMessagePack` directly (faster, no intermediate).

(
    value: &T,
)

Source from the content-addressed store, hash-verified

29/// to MessagePack. Use `encode()` for types that implement `ToMessagePack`
30/// directly (faster, no intermediate).
31pub(in crate::data::executor) fn encode_serde<T: serde::Serialize>(
32 value: &T,
33) -> crate::Result<Vec<u8>> {
34 let json_value = serde_json::to_value(value).map_err(|e| crate::Error::Codec {
35 detail: format!("serde serialization: {e}"),
36 })?;
37 encode_json(&json_value)
38}
39
40/// Encode a Vec of serde_json::Value as MessagePack bytes.
41pub(in crate::data::executor) fn encode_json_vec(

Callers 3

dispatch_metaMethod · 0.85

Calls 1

encode_jsonFunction · 0.85

Tested by

no test coverage detected