Search in sources :

Example 11 with MySQLMessage

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());
}
Also used : MySQLMessage(io.mycat.backend.mysql.MySQLMessage) Test(org.junit.Test)

Example 12 with MySQLMessage

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();
    }
}
Also used : MySQLMessage(io.mycat.backend.mysql.MySQLMessage)

Example 13 with MySQLMessage

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;
}
Also used : ArrayList(java.util.ArrayList) MySQLMessage(io.mycat.backend.mysql.MySQLMessage)

Example 14 with MySQLMessage

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");
    }
}
Also used : MySQLMessage(io.mycat.backend.mysql.MySQLMessage)

Example 15 with MySQLMessage

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();
}
Also used : MySQLMessage(io.mycat.backend.mysql.MySQLMessage)

Aggregations

MySQLMessage (io.mycat.backend.mysql.MySQLMessage)56 Test (org.junit.Test)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ByteBuffer (java.nio.ByteBuffer)4 BindValue (io.mycat.backend.mysql.BindValue)2 BufferHolder (io.mycat.memory.unsafe.row.BufferHolder)2 UnsafeRow (io.mycat.memory.unsafe.row.UnsafeRow)2 UnsafeRowWriter (io.mycat.memory.unsafe.row.UnsafeRowWriter)2 EOFPacket (io.mycat.net.mysql.EOFPacket)2 ServerConnection (io.mycat.server.ServerConnection)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2