database-mesh/pisanix

Why the MySQL EOF and OK protocol length need add 4?

dongzl opened this issue · 4 comments

Question

#[inline]
pub fn is_eof(data: &[u8]) -> bool {
    data.len() < 9 + 4 && *unsafe { data.get_unchecked(4) } == EOF_HEADER
}

#[inline]
pub fn is_ok(data: &[u8]) -> bool {
    data.len() > 7 + 4 && *unsafe { data.get_unchecked(4) } == OK_HEADER
}

https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_ok_packet.html

These rules distinguish whether the packet represents OK or EOF:

OK: header = 0 and length of packet > 7
EOF: header = 0xfe and length of packet < 9

4 means length of header,I think length of packet means the length of payload, otherwise this don't need to add 4 here.

https://dev.mysql.com/doc/internals/en/packet-EOF_Packet.html

In this doc, I think 9 length packet include the header.

image

wbtlb commented

hi @dongzl
In this example,the 4 bytes is header packet,the data length is 5 bytes. The length of payload is 9 bytes.
You are right, could you please commit a pr to fix this issue?

hi @dongzl In this example,the 4 bytes is header packet,the data lenght is 5 bytes. The length of payload is 9 bytes. You are right, could you please commit a pr to fix this issue?

OK, I will fix it.