mysql通訊封包結構
類型 | 名字 | 描述 |
---|---|---|
)3個字節的個字節(3個字元payload和1位元組的序號組合成封包頭 | int | |
string |
||
string | load |
load
if(NULL){ 0xfb }else{ Protocol::LengthEncodedString }🎜ResultsetRow包類🎜
public class ResultsetRowPacket extends MySQLPacket { private static final byte NULL_MARK = (byte) 251; public int columnCount; public List<byte[]> columnValues; public ResultsetRowPacket() { } public ResultsetRowPacket(int columnCount) { this.columnCount = columnCount; } @Override public void read(byte[] data) { MySQLMessage mm = new MySQLMessage(data); packetLength = mm.readUB3(); packetId = mm.read(); for (int i = 0; i < columnCount; i++) { columnValues.add(mm.readBytesWithLength()); } } @Override public void write(ByteBuffer buffer) { BufferUtil.writeUB3(buffer, calcPacketSize()); buffer.put(packetId); for (int i = 0; i < columnCount; i++) { byte[] fv = columnValues.get(i); if (fv == null) { buffer.put(NULL_MARK); } else { BufferUtil.writeLength(buffer, fv.length); buffer.put(fv); } } } @Override public int calcPacketSize() { int size = 0; for (int i = 0; i < columnCount; i++) { byte[] v = columnValues.get(i); size += (v == null || v.length == 0) ? 1 : BufferUtil.getLength(v); } return size; } @Override protected String getPacketInfo() { return "MySQL Resultset Row Packet"; } }🎜ColumnDefinition包🎜🎜 ee🎜ColumnCount套件類別🎜
lenenc_str catalog lenenc_str schema lenenc_str table lenenc_str org_table lenenc_str name lenenc_str org_name lenenc_int length of fixed-length fields [0c] 2 character set 4 column length 1 type 2 flags 1 decimals 2 filler [00] [00] if command was COM_FIELD_LIST { lenenc_int length of default-values string[$len] default values }🎜🎜🎜