Skip to content

Commit

Permalink
Fix code inspections for db-protocol modules
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed May 25, 2024
1 parent 8e959eb commit dc28a48
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ private static BigDecimal toDecimal(final DecimalMetaData metaData, final byte[]
private static BigDecimal decodeIntegerValue(final DecimalMetaData metaData, final byte[] value) {
int offset = DIG_TO_BYTES[metaData.getExtraIntegerSize()];
BigDecimal result = offset > 0 ? BigDecimal.valueOf(readFixedLengthIntBE(value, 0, offset)) : BigDecimal.ZERO;
for (; offset < metaData.getIntegerByteLength(); offset += DEC_BYTE_SIZE) {
while (offset < metaData.getIntegerByteLength()) {
int i = readFixedLengthIntBE(value, offset, DEC_BYTE_SIZE);
result = result.movePointRight(DIG_PER_DEC).add(BigDecimal.valueOf(i));
offset += DEC_BYTE_SIZE;
}
return result;
}
Expand All @@ -73,8 +74,10 @@ private static BigDecimal decodeScaleValue(final DecimalMetaData metaData, final
int shift = 0;
int offset = metaData.getIntegerByteLength();
int scale = metaData.getScale();
for (; shift + DIG_PER_DEC <= scale; shift += DIG_PER_DEC, offset += DEC_BYTE_SIZE) {
while (shift + DIG_PER_DEC <= scale) {
result = result.add(BigDecimal.valueOf(readFixedLengthIntBE(value, offset, DEC_BYTE_SIZE)).movePointLeft(shift + DIG_PER_DEC));
shift += DIG_PER_DEC;
offset += DEC_BYTE_SIZE;
}
if (shift < scale) {
result = result.add(BigDecimal.valueOf(readFixedLengthIntBE(value, offset, DIG_TO_BYTES[scale - shift])).movePointLeft(scale));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,14 @@ private static String decodeString(final ByteBuf byteBuf) {

private static int decodeDataLength(final ByteBuf byteBuf) {
int result = 0;
for (int i = 0;; i++) {
int i = 0;
while (true) {
int data = byteBuf.readUnsignedByte();
result |= (data & 0x7f) << (7 * i);
if (0 == (data & 0x80)) {
break;
}
i++;
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@
* @see <a href="https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase_packets_protocol_auth_switch_request.html">AuthSwitchRequest</a>
*/
@RequiredArgsConstructor
@Getter
public final class MySQLAuthSwitchRequestPacket extends MySQLPacket {

/**
* Header of MySQL auth switch request packet.
*/
public static final int HEADER = 0xfe;

@Getter
private final String authPluginName;

@Getter
private final MySQLAuthenticationPluginData authPluginData;

public MySQLAuthSwitchRequestPacket(final MySQLPacketPayload payload) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,11 @@ private byte[] codecDataLength(final int length) {
}
// compress
int index = lengthData.length - 1;
for (; index > 0; index--) {
while (index > 0) {
if (0 != lengthData[index]) {
break;
}
index--;
}
for (int i = 0; i < index; i++) {
lengthData[i] |= 0x80;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
* Unsupported command packet for PostgreSQL.
*/
@RequiredArgsConstructor
@Getter
public final class PostgreSQLUnsupportedCommandPacket extends PostgreSQLCommandPacket {

@Getter
private final PostgreSQLIdentifierTag identifier;

@Override
Expand Down

0 comments on commit dc28a48

Please sign in to comment.