Search in sources :

Example 1 with MySQLPayloadWriter

use of io.mycat.beans.mysql.MySQLPayloadWriter in project Mycat2 by MyCATApache.

the class MySQLPacketUtil method generateAuthenticationSwitchRequest.

public static final byte[] generateAuthenticationSwitchRequest(String authenticationPluginName, byte[] authenticationPluginData) {
    try (MySQLPayloadWriter writer = new MySQLPayloadWriter(512)) {
        writer.writeFixInt(1, 0xfe);
        writer.writeNULString(authenticationPluginName);
        writer.write(authenticationPluginData);
        return writer.toByteArray();
    }
}
Also used : MySQLPayloadWriter(io.mycat.beans.mysql.MySQLPayloadWriter)

Example 2 with MySQLPayloadWriter

use of io.mycat.beans.mysql.MySQLPayloadWriter in project Mycat2 by MyCATApache.

the class MySQLPacketUtil method generateOk.

public static final byte[] generateOk(int header, int warningCount, int serverStatus, long affectedRows, long lastInsertId, boolean isClientProtocol41, boolean isKnowsAboutTransactions, boolean sessionVariableTracking, String message) {
    try (MySQLPayloadWriter writer = new MySQLPayloadWriter(12)) {
        writer.writeByte((byte) header);
        writer.writeLenencInt(affectedRows);
        writer.writeLenencInt(lastInsertId);
        writer.writeFixInt(2, serverStatus);
        writer.writeFixInt(2, warningCount);
        if (message == null) {
            message = "";
        }
        writer.writeEOFString(message);
        return writer.toByteArray();
    }
}
Also used : MySQLPayloadWriter(io.mycat.beans.mysql.MySQLPayloadWriter)

Example 3 with MySQLPayloadWriter

use of io.mycat.beans.mysql.MySQLPayloadWriter in project Mycat2 by MyCATApache.

the class MySQLPacketUtil method generateBinaryRow.

public static final byte[] generateBinaryRow(byte[][] rows) {
    final int columnCount = rows.length;
    final int binaryNullBitMapLength = (columnCount + 7 + 2) / 8;
    byte[] nullMap = new byte[binaryNullBitMapLength];
    final int payloayEstimateMaxSize = generateBinaryRowHeader(rows, nullMap);
    try (MySQLPayloadWriter writer = new MySQLPayloadWriter(payloayEstimateMaxSize)) {
        writer.write(00);
        writer.write(nullMap);
        for (byte[] row : rows) {
            if (row != null) {
                writer.write(row);
            }
        }
        return writer.toByteArray();
    }
}
Also used : MySQLPayloadWriter(io.mycat.beans.mysql.MySQLPayloadWriter)

Example 4 with MySQLPayloadWriter

use of io.mycat.beans.mysql.MySQLPayloadWriter in project Mycat2 by MyCATApache.

the class MySQLPacketUtil method generateError.

/**
 * 生成简单的错误包
 *
 * @param errno 必须正确设置,否则图形化客户端不会显示
 */
/**
 * @param errno                 the error code
 * @param message               the error massage
 * @param serverCapabilityFlags server capability
 * @return the data of payload
 */
public static final byte[] generateError(int errno, String message, int serverCapabilityFlags) {
    try (MySQLPayloadWriter writer = new MySQLPayloadWriter(64)) {
        ErrorPacketImpl errorPacket = new ErrorPacketImpl();
        if (message != null) {
            errorPacket.setErrorMessage(message.getBytes());
        }
        errorPacket.setErrorCode(errno);
        errorPacket.writePayload(writer, serverCapabilityFlags);
        return writer.toByteArray();
    }
}
Also used : MySQLPayloadWriter(io.mycat.beans.mysql.MySQLPayloadWriter)

Example 5 with MySQLPayloadWriter

use of io.mycat.beans.mysql.MySQLPayloadWriter in project Mycat2 by MyCATApache.

the class MySQLPacketUtil method generateMySQLPacket.

public static byte[] generateMySQLPacket(int packetId, MySQLPayloadWriter writer) {
    byte[] bytes = writer.toByteArray();
    try {
        Thread thread = Thread.currentThread();
        PacketSplitterImpl packetSplitter = new PacketSplitterImpl();
        int wholePacketSize = MySQLPacketSplitter.caculWholePacketSize(bytes.length);
        try (MySQLPayloadWriter byteArray = new MySQLPayloadWriter(wholePacketSize)) {
            packetSplitter.init(bytes.length);
            while (packetSplitter.nextPacketInPacketSplitter()) {
                int offset = packetSplitter.getOffsetInPacketSplitter();
                int len = packetSplitter.getPacketLenInPacketSplitter();
                byteArray.writeFixInt(3, len);
                byteArray.write(packetId);
                byteArray.write(bytes, offset, len);
                ++packetId;
            }
            return byteArray.toByteArray();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MySQLPayloadWriter(io.mycat.beans.mysql.MySQLPayloadWriter) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

MySQLPayloadWriter (io.mycat.beans.mysql.MySQLPayloadWriter)31 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 MycatMySQLRowMetaData (io.mycat.beans.mycat.MycatMySQLRowMetaData)2 AuthPacket (io.mycat.beans.mysql.packet.AuthPacket)2 AuthSwitchRequestPacket (io.mycat.beans.mysql.packet.AuthSwitchRequestPacket)2 Authenticator (io.mycat.Authenticator)1 MycatUser (io.mycat.MycatUser)1 HandshakePacket (io.mycat.beans.mysql.packet.HandshakePacket)1 MySQLPacket (io.mycat.beans.mysql.packet.MySQLPacket)1 MySQLServerCapabilityFlags (io.mycat.config.MySQLServerCapabilityFlags)1 UserConfig (io.mycat.config.UserConfig)1 Buffer (io.vertx.core.buffer.Buffer)1 SocketAddress (java.net.SocketAddress)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1