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();
}
}
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();
}
}
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();
}
}
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();
}
}
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);
}
}
Aggregations