https://github.com/sea-boat/mysql-protocol
# mysql客戶端可以用query套件向服務端發送一個基於文字查詢。
類型 | 名字 | 描述 |
---|---|---|
#int<3> | payload長度 | #按照the least significant byte first存儲,3個字節的payload和1個字節的序號組合成報文頭 |
int<1> | #序號 | |
payload | 報文體,長度即為前面指定的payload長度 |
1 [03] COM_QUERYstring[EOF] the query the server shall execute
/** * * <pre class="brush:php;toolbar:false"><b>mysql query packet.</b>* @author *
seaboat*
<b>email: </b>849586227@qq.com*
<b>blog: </b>http://www.php.cn/;/pre> * @version 1.0 * @see http://www.php.cn/ */public class QueryPacket extends MySQLPacket { public byte flag; public byte[] message; public void read(byte[] data) { MySQLMessage mm = new MySQLMessage(data); packetLength = mm.readUB3(); packetId = mm.read(); flag = mm.read(); message = mm.readBytes(); } public void write(ByteBuffer buffer) { int size = calcPacketSize(); BufferUtil.writeUB3(buffer, size); buffer.put(packetId); buffer.put(COM_QUERY); buffer.put(message); } @Override public int calcPacketSize() { int size = 1; if (message != null) { size += message.length; } return size; } @Override protected String getPacketInfo() { return "MySQL Query Packet"; } }