Skip to content

Commit 906079a

Browse files
committed
Move the Notification class that is PG specific to vertx-pg-client
1 parent 71b6cb7 commit 906079a

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/datatype/DataTypeCodec.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import io.vertx.core.buffer.Buffer;
2525
import io.vertx.sqlclient.Tuple;
2626
import io.vertx.sqlclient.data.Numeric;
27-
import io.vertx.sqlclient.impl.codec.CommonCodec;
27+
import io.vertx.sqlclient.impl.Utils;
2828

2929
import java.math.BigInteger;
3030
import java.nio.charset.Charset;
@@ -637,23 +637,23 @@ private static Object binaryDecodeJson(int collationId, ByteBuf buffer) {
637637
}
638638

639639
private static Byte textDecodeInt8(ByteBuf buffer, int index, int length) {
640-
return (byte) CommonCodec.decodeDecStringToLong(index, length, buffer);
640+
return (byte) Utils.decodeDecStringToLong(index, length, buffer);
641641
}
642642

643643
private static Short textDecodeInt16(ByteBuf buffer, int index, int length) {
644-
return (short) CommonCodec.decodeDecStringToLong(index, length, buffer);
644+
return (short) Utils.decodeDecStringToLong(index, length, buffer);
645645
}
646646

647647
private static Integer textDecodeInt24(ByteBuf buffer, int index, int length) {
648-
return (int) CommonCodec.decodeDecStringToLong(index, length, buffer);
648+
return (int) Utils.decodeDecStringToLong(index, length, buffer);
649649
}
650650

651651
private static Integer textDecodeInt32(ByteBuf buffer, int index, int length) {
652-
return (int) CommonCodec.decodeDecStringToLong(index, length, buffer);
652+
return (int) Utils.decodeDecStringToLong(index, length, buffer);
653653
}
654654

655655
private static Long textDecodeInt64(ByteBuf buffer, int index, int length) {
656-
return CommonCodec.decodeDecStringToLong(index, length, buffer);
656+
return Utils.decodeDecStringToLong(index, length, buffer);
657657
}
658658

659659
private static Float textDecodeFloat(int collationId, ByteBuf buffer, int index, int length) {

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/Notification.java renamed to vertx-pg-client/src/main/java/io/vertx/pgclient/impl/Notification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
package io.vertx.sqlclient.impl;
18+
package io.vertx.pgclient.impl;
1919

2020
import java.util.Objects;
2121

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgConnectionImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import io.vertx.pgclient.impl.codec.TxFailedEvent;
3030
import io.vertx.pgclient.spi.PgDriver;
3131
import io.vertx.sqlclient.spi.connection.Connection;
32-
import io.vertx.sqlclient.impl.Notification;
3332
import io.vertx.sqlclient.codec.SocketConnectionBase;
3433
import io.vertx.sqlclient.internal.SqlConnectionBase;
3534

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgSocketConnection.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import io.vertx.sqlclient.codec.CommandMessage;
3636
import io.vertx.sqlclient.codec.SocketConnectionBase;
3737
import io.vertx.sqlclient.spi.connection.Connection;
38-
import io.vertx.sqlclient.impl.Notification;
3938
import io.vertx.sqlclient.internal.PreparedStatement;
4039
import io.vertx.sqlclient.internal.QueryResultHandler;
4140
import io.vertx.sqlclient.spi.DatabaseMetadata;

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/DataTypeCodec.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import io.vertx.pgclient.impl.util.UTF8StringEndDetector;
3333
import io.vertx.sqlclient.Tuple;
3434
import io.vertx.sqlclient.data.Numeric;
35-
import io.vertx.sqlclient.impl.codec.CommonCodec;
35+
import io.vertx.sqlclient.impl.Utils;
3636

3737
import java.math.BigDecimal;
3838
import java.net.Inet4Address;
@@ -688,7 +688,7 @@ private static Boolean textDecodeBOOL(int index, int len, ByteBuf buff) {
688688
}
689689

690690
private static Short textDecodeINT2(int index, int len, ByteBuf buff) {
691-
return (short) CommonCodec.decodeDecStringToLong(index, len, buff);
691+
return (short) Utils.decodeDecStringToLong(index, len, buff);
692692
}
693693

694694
private static Short binaryDecodeINT2(int index, int len, ByteBuf buff) {
@@ -700,7 +700,7 @@ private static void binaryEncodeINT2(Number value, ByteBuf buff) {
700700
}
701701

702702
private static Integer textDecodeINT4(int index, int len, ByteBuf buff) {
703-
return (int) CommonCodec.decodeDecStringToLong(index, len, buff);
703+
return (int) Utils.decodeDecStringToLong(index, len, buff);
704704
}
705705

706706
private static Integer binaryDecodeINT4(int index, int len, ByteBuf buff) {
@@ -712,7 +712,7 @@ private static void binaryEncodeINT4(Number value, ByteBuf buff) {
712712
}
713713

714714
private static Long textDecodeINT8(int index, int len, ByteBuf buff) {
715-
return CommonCodec.decodeDecStringToLong(index, len, buff);
715+
return Utils.decodeDecStringToLong(index, len, buff);
716716
}
717717

718718
private static Long binaryDecodeINT8(int index, int len, ByteBuf buff) {

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/PgDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import io.netty.util.ByteProcessor;
2626
import io.vertx.core.Completable;
2727
import io.vertx.pgclient.impl.util.Util;
28-
import io.vertx.sqlclient.impl.Notification;
28+
import io.vertx.pgclient.impl.Notification;
2929
import io.vertx.sqlclient.codec.CommandResponse;
3030

3131
/**

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/Utils.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.vertx.sqlclient.impl;
22

3+
import io.netty.buffer.ByteBuf;
34
import io.vertx.core.Future;
45
import io.vertx.core.buffer.Buffer;
56
import io.vertx.core.json.JsonArray;
@@ -69,4 +70,34 @@ public Future<T> get() {
6970
public static <T> Supplier<Future<T>> singletonSupplier(T factory) {
7071
return () -> Future.succeededFuture(factory);
7172
}
73+
74+
/**
75+
* Decode the specified {@code buff} formatted as a decimal string starting at the readable index
76+
* with the specified {@code length} to a long.
77+
*
78+
* @param index the hex string index
79+
* @param len the hex string length
80+
* @param buff the byte buff to read from
81+
* @return the decoded value as a long
82+
*/
83+
public static long decodeDecStringToLong(int index, int len, ByteBuf buff) {
84+
long value = 0;
85+
if (len > 0) {
86+
int to = index + len;
87+
boolean neg = false;
88+
if (buff.getByte(index) == '-') {
89+
neg = true;
90+
index++;
91+
}
92+
while (index < to) {
93+
byte ch = buff.getByte(index++);
94+
byte nibble = (byte) (ch - '0');
95+
value = value * 10 + nibble;
96+
}
97+
if (neg) {
98+
value = -value;
99+
}
100+
}
101+
return value;
102+
}
72103
}

0 commit comments

Comments
 (0)