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

Function encode

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

Generic encoders for Data Plane response payloads, plus the `decode_payload_to_json` transcoder used at the Control Plane boundary. Serialize a response payload as MessagePack bytes. Drop-in replacement for `serde_json::to_vec(&value)` in handler code. Returns MessagePack bytes that are 30-50% smaller and 2-3x faster to produce than JSON.

(
    value: &T,
)

Source from the content-addressed store, hash-verified

9/// Returns MessagePack bytes that are 30-50% smaller and 2-3x faster to
10/// produce than JSON.
11pub(in crate::data::executor) fn encode<T: zerompk::ToMessagePack>(
12 value: &T,
13) -> crate::Result<Vec<u8>> {
14 zerompk::to_msgpack_vec(value).map_err(|e| crate::Error::Codec {
15 detail: format!("response serialization: {e}"),
16 })
17}
18
19/// Encode a serde_json::Value payload as MessagePack bytes.
20pub(in crate::data::executor) fn encode_json(value: &serde_json::Value) -> crate::Result<Vec<u8>> {

Callers 4

encode_vector_hitsFunction · 0.70
meta_query_last_valueMethod · 0.50
value_to_jsonFunction · 0.50

Calls

no outgoing calls

Tested by 1

encode_vector_hitsFunction · 0.56