Why the MySQL EOF and OK protocol length need add 4?
dongzl opened this issue · 4 comments
dongzl commented
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
xuanyuan300 commented
4 means length of header,I think length of packet
means the length of payload, otherwise this don't need to add 4 here.
dongzl commented
https://dev.mysql.com/doc/internals/en/packet-EOF_Packet.html
In this doc, I think 9 length packet
include the header
.