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

Function write_frame

nodedb-cluster/src/rpc_codec/header.rs:36–49  ·  view source on GitHub ↗

Write a framed v3 header + payload into `out`. `rpc_type` is the discriminant byte; `payload` is the already-serialized body. The current cluster epoch (read from [`current_local_cluster_epoch`]) is stamped into the header.

(rpc_type: u8, payload: &[u8], out: &mut Vec<u8>)

Source from the content-addressed store, hash-verified

34/// body. The current cluster epoch (read from
35/// [`current_local_cluster_epoch`]) is stamped into the header.
36pub fn write_frame(rpc_type: u8, payload: &[u8], out: &mut Vec<u8>) -> Result<()> {
37 let payload_len: u32 = payload.len().try_into().map_err(|_| ClusterError::Codec {
38 detail: format!("payload too large: {} bytes", payload.len()),
39 })?;
40 let crc = crc32c::crc32c(payload);
41 let epoch = current_local_cluster_epoch();
42 out.push(RPC_FRAME_VERSION);
43 out.push(rpc_type);
44 out.extend_from_slice(&payload_len.to_le_bytes());
45 out.extend_from_slice(&crc.to_le_bytes());
46 out.extend_from_slice(&epoch.to_le_bytes());
47 out.extend_from_slice(payload);
48 Ok(())
49}
50
51/// Validate the CRC32C of an inbound frame and return the payload slice.
52///

Callers 15

encode_execute_reqFunction · 0.70
encode_execute_respFunction · 0.70
encode_data_propose_reqFunction · 0.70
encode_data_propose_respFunction · 0.70
encode_vshard_envelopeFunction · 0.70
encode_join_reqFunction · 0.70
encode_join_respFunction · 0.70
encode_pingFunction · 0.70
encode_pongFunction · 0.70

Calls 3

lenMethod · 0.45
pushMethod · 0.45

Tested by 1