Skip to content

Commit

Permalink
Make QuicConnectionAddress.toString() method more useful (java-native…
Browse files Browse the repository at this point in the history
…-access#339)


Motivation:

The toString() method of QuicConnectionAddress did produce a not so useful string representation.

Modifications:

Use a hexdump presentation of the id

Result:

Fixes netty/netty-incubator-codec-quic#338
  • Loading branch information
normanmaurer authored Oct 11, 2021
1 parent 57af932 commit 93ba542
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
package io.netty.incubator.codec.quic;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;

import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.util.Objects;
Expand All @@ -30,6 +34,8 @@ public final class QuicConnectionAddress extends SocketAddress {
*/
public static final QuicConnectionAddress EPHEMERAL = new QuicConnectionAddress((ByteBuffer) null, false);

private final String toStr;

// Accessed by QuicheQuicheChannel
final ByteBuffer connId;

Expand Down Expand Up @@ -62,15 +68,22 @@ private QuicConnectionAddress(ByteBuffer connId, boolean validate) {
+ Quiche.QUICHE_MAX_CONN_ID_LEN);
}
this.connId = connId;
if (connId == null) {
toStr = "QuicConnectionAddress{EPHEMERAL}";
} else {
ByteBuf buffer = Unpooled.wrappedBuffer(connId);
try {
toStr = "QuicConnectionAddress{" +
"connId=" + ByteBufUtil.hexDump(buffer) + '}';
} finally {
buffer.release();
}
}
}

@Override
public String toString() {
if (this == EPHEMERAL) {
return "QuicConnectionAddress{EPHEMERAL}";
}
return "QuicConnectionAddress{" +
"connId=" + connId + '}';
return toStr;
}

@Override
Expand Down

0 comments on commit 93ba542

Please sign in to comment.