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

Function encode_json_frame

nodedb/tests/startup_gate_native.rs:50–56  ·  view source on GitHub ↗

Encode a JSON payload as a native protocol frame (4-byte length prefix).

(json: &[u8])

Source from the content-addressed store, hash-verified

48
49/// Encode a JSON payload as a native protocol frame (4-byte length prefix).
50fn encode_json_frame(json: &[u8]) -> Vec<u8> {
51 let mut frame = Vec::with_capacity(4 + json.len());
52 let len = json.len() as u32;
53 frame.extend_from_slice(&len.to_be_bytes());
54 frame.extend_from_slice(json);
55 frame
56}
57
58/// Read one native protocol frame from a stream (4-byte length prefix + payload).
59async fn read_json_frame(stream: &mut TcpStream) -> Vec<u8> {

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected