6
6
import io .netty .channel .ChannelHandlerContext ;
7
7
import io .netty .handler .codec .ByteToMessageCodec ;
8
8
import java .io .IOException ;
9
+ import java .nio .charset .StandardCharsets ;
9
10
import java .util .List ;
10
11
import org .slf4j .Logger ;
11
12
import org .slf4j .LoggerFactory ;
@@ -24,6 +25,7 @@ public BinaryHandler(HomekitClientConnection connection) {
24
25
@ Override
25
26
protected void encode (ChannelHandlerContext ctx , ByteBuf msg , ByteBuf out ) throws Exception {
26
27
if (started ) {
28
+ debugData ("Sending data" , msg , ctx );
27
29
byte [] b = new byte [msg .readableBytes ()];
28
30
msg .readBytes (b );
29
31
out .writeBytes (connection .encryptResponse (b ));
@@ -38,6 +40,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
38
40
in .readBytes (b );
39
41
byte [] decrypted = connection .decryptRequest (b );
40
42
ByteBuf outBuf = Unpooled .copiedBuffer (decrypted );
43
+ debugData ("Received data" , outBuf , ctx );
41
44
out .add (outBuf );
42
45
started = true ;
43
46
}
@@ -52,4 +55,13 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
52
55
}
53
56
super .exceptionCaught (ctx , cause );
54
57
}
58
+
59
+ private void debugData (String msg , ByteBuf b , ChannelHandlerContext ctx ) throws Exception {
60
+ if (logger .isDebugEnabled ()) {
61
+ logger .debug (
62
+ String .format (
63
+ "%s [%s]:%n%s" ,
64
+ msg , ctx .channel ().remoteAddress ().toString (), b .toString (StandardCharsets .UTF_8 )));
65
+ }
66
+ }
55
67
}
0 commit comments