use of io.mycat.beans.mysql.MySQLPayloadWriter in project Mycat2 by MyCATApache.
the class MySQLPacketUtil method generatePreparePayloadRequest.
public static byte[] generatePreparePayloadRequest(byte[] sql) {
try (MySQLPayloadWriter byteArrayOutput = new MySQLPayloadWriter(1 + sql.length)) {
byteArrayOutput.writeByte(0x16);
byteArrayOutput.write(sql);
byte[] bytes = byteArrayOutput.toByteArray();
return bytes;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.mycat.beans.mysql.MySQLPayloadWriter in project Mycat2 by MyCATApache.
the class MySQLPacketUtil method generateComQuery.
public static final byte[] generateComQuery(String sql) {
try (MySQLPayloadWriter writer = new MySQLPayloadWriter(sql.length() + 5)) {
writer.write(0x3);
writer.writeEOFString(sql);
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, byte[] packet) {
try {
if (packet.length < PacketSplitterImpl.MAX_PACKET_SIZE) {
int wholePacketSize = MySQLPacketSplitter.caculWholePacketSize(packet.length);
try (MySQLPayloadWriter byteArray = new MySQLPayloadWriter(wholePacketSize)) {
int offset = 0;
int len = packet.length;
byteArray.writeFixInt(3, len);
byteArray.write(packetId);
byteArray.write(packet, offset, len);
++packetId;
return byteArray.toByteArray();
}
} else {
PacketSplitterImpl packetSplitter = new PacketSplitterImpl();
int wholePacketSize = MySQLPacketSplitter.caculWholePacketSize(packet.length);
try (MySQLPayloadWriter byteArray = new MySQLPayloadWriter(wholePacketSize)) {
packetSplitter.init(packet.length);
while (packetSplitter.nextPacketInPacketSplitter()) {
int offset = packetSplitter.getOffsetInPacketSplitter();
int len = packetSplitter.getPacketLenInPacketSplitter();
byteArray.writeFixInt(3, len);
byteArray.write(packetId);
byteArray.write(packet, offset, len);
++packetId;
}
return byteArray.toByteArray();
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.mycat.beans.mysql.MySQLPayloadWriter in project Mycat2 by MyCATApache.
the class MySQLPacketUtil method generateSSLRequest.
public static final byte[] generateSSLRequest(int clientCapacities, int maxPacketSize, int characterCollation, String reserved, int extendedClientCapabilitles, String reserved2) {
try (MySQLPayloadWriter writer = new MySQLPayloadWriter(512)) {
writer.writeFixInt(4, clientCapacities);
writer.writeFixInt(4, maxPacketSize);
writer.writeFixInt(1, characterCollation);
writer.write(reserved.getBytes());
if (MySQLServerCapabilityFlags.isLongPassword(clientCapacities)) {
writer.writeFixInt(4, extendedClientCapabilitles);
} else {
writer.write(reserved2.getBytes());
}
return writer.toByteArray();
}
}
use of io.mycat.beans.mysql.MySQLPayloadWriter in project Mycat2 by MyCATApache.
the class MySQLPacketUtil method generateAllColumnDefPayload.
// public static final byte[] generateColumnDefPayload(ResultSetMetaData metaData, int columnIndex) {
// try (MySQLPayloadWriter writer = new MySQLPayloadWriter(128)) {
// ColumnDefPacketImpl columnDefPacket = new ColumnDefPacketImpl(metaData, columnIndex);
// columnDefPacket.writePayload(writer);
// return writer.toByteArray();
// }
// }
public static final Iterable<byte[]> generateAllColumnDefPayload(MycatRowMetaData metaData) {
List<byte[]> list = new ArrayList<>(metaData.getColumnCount());
final int count = metaData.getColumnCount();
if (metaData instanceof MycatMySQLRowMetaData) {
List<ColumnDefPacketImpl> columnDefPackets = (List) ((MycatMySQLRowMetaData) metaData).getColumnDefPackets();
for (int index = 0; index < count; index++) {
try (MySQLPayloadWriter writer = new MySQLPayloadWriter(128)) {
columnDefPackets.get(index).writePayload(writer);
list.add(writer.toByteArray());
}
}
} else {
for (int index = 0; index < count; index++) {
list.add(MySQLPacketUtil.generateColumnDefPayload(metaData, index));
}
}
return list;
}
Aggregations