package com.cisdi.data.OBLF.util;

import io.netty.buffer.ByteBuf;
import lombok.extern.slf4j.Slf4j;

import static io.netty.buffer.ByteBufUtil.appendPrettyHexDump;
import static io.netty.util.internal.StringUtil.NEWLINE;

/**
 * @author cuianbing
 * @version 1.0
 * @description: TODO
 * @date 2021/7/9 15:32
 */
@Slf4j
public class ByteBufUtil {
    public static void log(ByteBuf byteBuf) {
        int length = byteBuf.readableBytes();
        int row = length / 16 + (length % 15 == 0 ? 0 : 1) + 4;
        StringBuilder buf = new StringBuilder(row * 80 * 2)
                .append("read index:").append(byteBuf.readerIndex())
                .append("  write index:").append(byteBuf.writerIndex())
                .append("  capacity:").append(byteBuf.capacity())
                .append(NEWLINE);
        appendPrettyHexDump(buf, byteBuf);
        log.info(buf.toString());
    }
}
