Example usage for io.netty.buffer ByteBufUtil prettyHexDump

List of usage examples for io.netty.buffer ByteBufUtil prettyHexDump

Introduction

In this page you can find the example usage for io.netty.buffer ByteBufUtil prettyHexDump.

Prototype

public static String prettyHexDump(ByteBuf buffer) 

Source Link

Document

Returns a multi-line hexadecimal dump of the specified ByteBuf that is easy to read by humans.

Usage

From source file:pl.tcs.btppllib.OcitResponseTelegramHandler.java

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
    ByteBuf buf = (ByteBuf) msg; // (1)
    log.debug("****** Message received ******");
    log.debug(ByteBufUtil.prettyHexDump(buf));
    log.debug("******************************");

    final int bufLen = buf.readableBytes();

    if (bufLen < 18) {
        throw new CriticalException(String.format("Incomplete telegram received [size]=%d", bufLen));
    }/*from www .j a v a 2 s .  c om*/

    try {
        // member = 6, otype = 8, method = 10
        int memberPos = 6, otypePos = 8, methodPos = 10;

        final int member = buf.getUnsignedShort(memberPos);
        final int otype = buf.getUnsignedShort(otypePos);
        final int method = buf.getUnsignedShort(methodPos);

        Class handlerClazz = HandlersMapping.getResponseHandler(member, otype, method);
        if (handlerClazz != null) {
            log.debug(String.format("Found response handler for member=%d otype=%d method=%d with name=%s",
                    member, otype, method, handlerClazz.getSimpleName()));

            OcitResponseTelegram resp = (OcitResponseTelegram) handlerClazz.newInstance();
            resp.fromByteBuf(buf); // initialize fields

            List<ResponseTelegramAction> allActions = resp.getActions();
            for (ResponseTelegramAction action : allActions) {
                executor.submit(action);
            }
        }
    } catch (InstantiationException | IllegalAccessException e) {
        throw new CriticalException(e);
    } finally {
        buf.release();
    }
}