首頁 >資料庫 >mysql教程 >mysql 協定的幾種套件及解析

mysql 協定的幾種套件及解析

伊谢尔伦
伊谢尔伦原創
2017-02-03 15:02:001309瀏覽

   mysql通訊封包結構

序號load
類型 名字 描述
)3個字節的個字節(3個字元payload和1位元組的序號組合成封包頭 int

string
string load
string

load

string

load

string

load

string


load

🎜🎜🎜string🎜🎜load🎜🎜🎜🎜 🎜🎜ResultsetRow包🎜🎜Payload🎜
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
  }
🎜🎜🎜
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn