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

Function decode

nodedb-cluster/src/rpc_codec/raft_rpc.rs:109–144  ·  view source on GitHub ↗

Decode a framed binary message into a [`RaftRpc`].

(data: &[u8])

Source from the content-addressed store, hash-verified

107
108/// Decode a framed binary message into a [`RaftRpc`].
109pub fn decode(data: &[u8]) -> Result<RaftRpc> {
110 let (rpc_type, payload) = super::header::parse_frame(data)?;
111 match rpc_type {
112 RPC_APPEND_ENTRIES_REQ => raft_msgs::decode_append_entries_req(payload),
113 RPC_APPEND_ENTRIES_RESP => raft_msgs::decode_append_entries_resp(payload),
114 RPC_REQUEST_VOTE_REQ => raft_msgs::decode_request_vote_req(payload),
115 RPC_REQUEST_VOTE_RESP => raft_msgs::decode_request_vote_resp(payload),
116 RPC_INSTALL_SNAPSHOT_REQ => raft_msgs::decode_install_snapshot_req(payload),
117 RPC_INSTALL_SNAPSHOT_RESP => raft_msgs::decode_install_snapshot_resp(payload),
118 RPC_JOIN_REQ => cluster_mgmt::decode_join_req(payload),
119 RPC_JOIN_RESP => cluster_mgmt::decode_join_resp(payload),
120 RPC_PING => cluster_mgmt::decode_ping(payload),
121 RPC_PONG => cluster_mgmt::decode_pong(payload),
122 RPC_TOPOLOGY_UPDATE => cluster_mgmt::decode_topology_update(payload),
123 RPC_TOPOLOGY_ACK => cluster_mgmt::decode_topology_ack(payload),
124 // Discriminants 13/14 (ForwardRequest/ForwardResponse) are retired.
125 // A node receiving these has a peer still running an older version.
126 // Return a typed error so the operator sees a clear message.
127 RPC_FORWARD_REQ | RPC_FORWARD_RESP => Err(ClusterError::Codec {
128 detail: format!(
129 "rpc_type {rpc_type} is a retired wire variant (ForwardRequest/ForwardResponse, \
130 retired in C-δ.6); upgrade all cluster nodes to remove this peer"
131 ),
132 }),
133 RPC_VSHARD_ENVELOPE => vshard::decode_vshard_envelope(payload),
134 RPC_METADATA_PROPOSE_REQ => metadata::decode_metadata_propose_req(payload),
135 RPC_METADATA_PROPOSE_RESP => metadata::decode_metadata_propose_resp(payload),
136 RPC_EXECUTE_REQ => execute::decode_execute_req(payload),
137 RPC_EXECUTE_RESP => execute::decode_execute_resp(payload),
138 RPC_DATA_PROPOSE_REQ => data_propose::decode_data_propose_req(payload),
139 RPC_DATA_PROPOSE_RESP => data_propose::decode_data_propose_resp(payload),
140 _ => Err(ClusterError::Codec {
141 detail: format!("unknown rpc_type: {rpc_type}"),
142 }),
143 }
144}
145
146/// Return the total frame size for a buffer that starts with a valid header.
147pub fn frame_size(header: &[u8; HEADER_SIZE]) -> Result<usize> {

Callers 10

roundtrip_reqFunction · 0.70
roundtrip_respFunction · 0.70
versioned_decodeFunction · 0.70
crc_corruption_detectedFunction · 0.70
truncated_frame_rejectedFunction · 0.70
roundtripFunction · 0.70
roundtripFunction · 0.70

Calls 15

parse_frameFunction · 0.85
decode_request_vote_reqFunction · 0.85
decode_request_vote_respFunction · 0.85
decode_join_reqFunction · 0.85
decode_join_respFunction · 0.85
decode_pingFunction · 0.85
decode_pongFunction · 0.85
decode_topology_updateFunction · 0.85

Tested by 5

crc_corruption_detectedFunction · 0.56
truncated_frame_rejectedFunction · 0.56