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>)
| 34 | /// body. The current cluster epoch (read from |
| 35 | /// [`current_local_cluster_epoch`]) is stamped into the header. |
| 36 | pub 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 | /// |