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

Function decode_request

nodedb/src/control/server/native/codec.rs:85–96  ·  view source on GitHub ↗

Decode a request payload according to the detected format.

(payload: &[u8], format: FrameFormat)

Source from the content-addressed store, hash-verified

83
84/// Decode a request payload according to the detected format.
85pub fn decode_request(payload: &[u8], format: FrameFormat) -> crate::Result<NativeRequest> {
86 match format {
87 FrameFormat::Json => sonic_rs::from_slice(payload).map_err(|e| crate::Error::BadRequest {
88 detail: format!("invalid JSON request: {e}"),
89 }),
90 FrameFormat::MessagePack => {
91 zerompk::from_msgpack(payload).map_err(|e| crate::Error::BadRequest {
92 detail: format!("invalid MessagePack request: {e}"),
93 })
94 }
95 }
96}
97
98/// Encode a response in the given format.
99pub fn encode_response(resp: &NativeResponse, format: FrameFormat) -> crate::Result<Vec<u8>> {

Callers 3

json_roundtripFunction · 0.70
msgpack_roundtripFunction · 0.70
runMethod · 0.70

Calls

no outgoing calls

Tested by 2

json_roundtripFunction · 0.56
msgpack_roundtripFunction · 0.56