use of io.mycat.backend.mysql.MySQLMessage in project Mycat_plus by coderczp.
the class MySQLMessageTest method testReadBytesWithNull2.
@Test
public void testReadBytesWithNull2() {
byte[] bytes = new byte[] { 0, 1, 2, 3, 0, 5 };
MySQLMessage message = new MySQLMessage(bytes);
byte[] ab = message.readBytesWithNull();
Assert.assertEquals(0, ab.length);
Assert.assertEquals(1, message.position());
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat_plus by coderczp.
the class ResultSetHeaderPacket method read.
public void read(byte[] data) {
MySQLMessage mm = new MySQLMessage(data);
this.packetLength = mm.readUB3();
this.packetId = mm.read();
this.fieldCount = (int) mm.readLength();
if (mm.hasRemaining()) {
this.extra = mm.readLength();
}
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat_plus by coderczp.
the class CompressUtil method splitPack.
/**
* 分包处理
*
* @param in
* @param decompressUnfinishedDataQueue
* @return
*/
private static List<byte[]> splitPack(byte[] in, ConcurrentLinkedQueue<byte[]> decompressUnfinishedDataQueue) {
// 合并
in = mergeBytes(in, decompressUnfinishedDataQueue);
List<byte[]> smallPackList = new ArrayList<>();
MySQLMessage msg = new MySQLMessage(in);
while (msg.hasRemaining()) {
int readLength = msg.length() - msg.position();
int packetLength = 0;
if (readLength > 3) {
packetLength = msg.readUB3();
msg.move(-3);
}
if (readLength < packetLength + 4) {
byte[] packet = msg.readBytes(readLength);
if (packet.length != 0) {
decompressUnfinishedDataQueue.add(packet);
}
} else {
byte[] packet = msg.readBytes(packetLength + 4);
if (packet.length != 0) {
smallPackList.add(packet);
}
}
}
return smallPackList;
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class FrontendCommandHandler method handle.
@Override
public void handle(byte[] data) {
if (source.getLoadDataInfileHandler() != null && source.getLoadDataInfileHandler().isStartLoadData()) {
MySQLMessage mm = new MySQLMessage(data);
int packetLength = mm.readUB3();
if (packetLength + 4 == data.length) {
source.loadDataInfileData(data);
}
return;
}
switch(data[4]) {
case MySQLPacket.COM_INIT_DB:
commands.doInitDB();
source.initDB(data);
break;
case MySQLPacket.COM_QUERY:
commands.doQuery();
source.query(data);
break;
case MySQLPacket.COM_PING:
commands.doPing();
source.ping();
break;
case MySQLPacket.COM_QUIT:
commands.doQuit();
source.close("quit cmd");
break;
case MySQLPacket.COM_PROCESS_KILL:
commands.doKill();
source.kill(data);
break;
case MySQLPacket.COM_STMT_PREPARE:
commands.doStmtPrepare();
source.stmtPrepare(data);
break;
case MySQLPacket.COM_STMT_SEND_LONG_DATA:
commands.doStmtSendLongData();
source.stmtSendLongData(data);
break;
case MySQLPacket.COM_STMT_RESET:
commands.doStmtReset();
source.stmtReset(data);
break;
case MySQLPacket.COM_STMT_EXECUTE:
commands.doStmtExecute();
source.stmtExecute(data);
break;
case MySQLPacket.COM_STMT_CLOSE:
commands.doStmtClose();
source.stmtClose(data);
break;
case MySQLPacket.COM_HEARTBEAT:
commands.doHeartbeat();
source.heartbeat(data);
break;
default:
commands.doOther();
source.writeErrMessage(ErrorCode.ER_UNKNOWN_COM_ERROR, "Unknown command");
}
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class ErrorPacket method read.
public void read(BinaryPacket bin) {
packetLength = bin.packetLength;
packetId = bin.packetId;
MySQLMessage mm = new MySQLMessage(bin.data);
fieldCount = mm.read();
errno = mm.readUB2();
if (mm.hasRemaining() && (mm.read(mm.position()) == SQLSTATE_MARKER)) {
mm.read();
sqlState = mm.readBytes(5);
}
message = mm.readBytes();
}
Aggregations