zero_mysql/protocol/command/
resultset.rs

1use crate::error::Result;
2use crate::protocol::BinaryRowPayload;
3use crate::protocol::primitive::*;
4use crate::value::NullBitmap;
5
6/// Result set metadata header
7#[derive(Debug, Clone)]
8pub struct ResultSetHeader {
9    pub column_count: u64,
10}
11
12/// Read binary protocol result set header (column count)
13pub fn read_binary_resultset_header(payload: &[u8]) -> Result<ResultSetHeader> {
14    let (column_count, _rest) = read_int_lenenc(payload)?;
15    Ok(ResultSetHeader { column_count })
16}
17
18/// Read binary protocol row or EOF
19/// Returns None if this is an EOF packet
20pub fn read_binary_row<'a>(payload: &'a [u8], num_columns: usize) -> Result<BinaryRowPayload<'a>> {
21    // Binary protocol row packet starts with 0x00
22    let (header, mut data) = read_int_1(payload)?;
23    debug_assert_eq!(header, 0x00);
24
25    // NULL bitmap: (num_columns + 7 + 2) / 8 bytes
26    // The +2 offset is for binary protocol
27    let null_bitmap_len = (num_columns + 7 + 2) >> 3;
28    let (null_bitmap, rest) = read_string_fix(data, null_bitmap_len)?;
29    data = rest;
30
31    // Remaining data is the values
32    Ok(BinaryRowPayload::new(
33        NullBitmap::for_result_set(null_bitmap),
34        data,
35        num_columns,
36    ))
37}