Read a single pgwire message from the stream. Returns `(type_byte, payload)` where payload excludes the 4-byte length field.
(r: &mut R)
| 158 | /// Read a single pgwire message from the stream. |
| 159 | /// Returns `(type_byte, payload)` where payload excludes the 4-byte length field. |
| 160 | async fn read_pg_message<R: AsyncReadExt + Unpin>(r: &mut R) -> (u8, Vec<u8>) { |
| 161 | let mut header = [0u8; 5]; |
| 162 | r.read_exact(&mut header).await.expect("read msg header"); |
| 163 | let msg_type = header[0]; |
| 164 | let length = u32::from_be_bytes(header[1..5].try_into().unwrap()) as usize; |
| 165 | let payload_len = length.saturating_sub(4); |
| 166 | let mut payload = vec![0u8; payload_len]; |
| 167 | if payload_len > 0 { |
| 168 | r.read_exact(&mut payload).await.expect("read msg payload"); |
| 169 | } |
| 170 | (msg_type, payload) |
| 171 | } |
| 172 | |
| 173 | // ── Test ────────────────────────────────────────────────────────────────── |
| 174 |
no test coverage detected