首頁  >  文章  >  資料庫  >  詳細介紹mysql 協定的ColumnCount包及解析

詳細介紹mysql 協定的ColumnCount包及解析

黄舟
黄舟原創
2017-03-07 13:30:081393瀏覽


git

#https://github.com/sea-boat/mysql-protocol


概況ColumnCount套件屬於服務端傳回ResultSet時的其中一部分套件。

mysql通訊封包結構

類型

###名字######描述########## #########int5bdf4c78156c7953567bb5a0aef2fc53######payload長度#######按照the least significant byte first存儲,3個字節的payload和1個字節的序號組合成報文頭############intf35d6e602fd7d0f0edfa6f7d103c1b57#######序號####################string ######payload######報文體,長度為前面指定的payload長度###############ColumnCount套件######### ###Payload#########
Protocol::LengthEncodedInteger
###更多詳情: http://dev.mysql.com/doc/internals/en/com-query-response.html#packet-ProtocolText:: ResultsetRow######ColumnCount套件類別###
/**
 * 
 * <pre class="brush:php;toolbar:false"><b>column count 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 ColumnCountPacket extends MySQLPacket {

    public int columnCount;    
    public void read(byte[] data) {
        MySQLMessage mm = new MySQLMessage(data);        
        this.packetLength = mm.readUB3();        
        this.packetId = mm.read();        
        this.columnCount = (int) mm.readLength();
    }    
    @Override
    public void write(ByteBuffer buffer) {        
    int size = calcPacketSize();
        BufferUtil.writeUB3(buffer, size);
        buffer.put(packetId);
        BufferUtil.writeLength(buffer, columnCount);
    }    
    @Override
    public int calcPacketSize() {        
    int size = BufferUtil.getLength(columnCount);        
    return size;
    }    @Override
    protected String getPacketInfo() {        
    return "MySQL Column Count Packet";
    }

}
### 以上就是詳細介紹mysql 協定的ColumnCount套件及解析的內容,更多相關內容請關注PHP中文網(www.php.cn)! ###
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn