git
https://github.com/sea-boat/mysql-protocol
概況
#ResultsetRow包屬於服務端傳回ResultSet時的其中一部分包,用於描述結果集的行記錄。
類型 | 名字 | 描述 |
---|---|---|
#int<3> | payload長度 | #按照the least significant byte first存儲,3個字節的payload和1個字節的序號組合成報文頭 |
int<1> | #序號 | |
payload | 封包文體,長度即為前面指定的payload長度 |
if(NULL){ 0xfb}else{ Protocol::LengthEncodedString}
/** * * <pre class="brush:php;toolbar:false"><b>resultset row 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 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"; } }