Encode a JSON payload as a native protocol frame (4-byte length prefix).
(json: &[u8])
| 48 | |
| 49 | /// Encode a JSON payload as a native protocol frame (4-byte length prefix). |
| 50 | fn 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). |
| 59 | async fn read_json_frame(stream: &mut TcpStream) -> Vec<u8> { |
no test coverage detected