66import io .netty .channel .ChannelHandlerContext ;
77import io .netty .handler .codec .ByteToMessageCodec ;
88import java .io .IOException ;
9+ import java .nio .charset .StandardCharsets ;
910import java .util .List ;
1011import org .slf4j .Logger ;
1112import org .slf4j .LoggerFactory ;
@@ -24,6 +25,7 @@ public BinaryHandler(HomekitClientConnection connection) {
2425 @ Override
2526 protected void encode (ChannelHandlerContext ctx , ByteBuf msg , ByteBuf out ) throws Exception {
2627 if (started ) {
28+ debugData ("Sending data" , msg , ctx );
2729 byte [] b = new byte [msg .readableBytes ()];
2830 msg .readBytes (b );
2931 out .writeBytes (connection .encryptResponse (b ));
@@ -38,6 +40,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
3840 in .readBytes (b );
3941 byte [] decrypted = connection .decryptRequest (b );
4042 ByteBuf outBuf = Unpooled .copiedBuffer (decrypted );
43+ debugData ("Received data" , outBuf , ctx );
4144 out .add (outBuf );
4245 started = true ;
4346 }
@@ -52,4 +55,13 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
5255 }
5356 super .exceptionCaught (ctx , cause );
5457 }
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+ }
5567}
0 commit comments