类 io.netty.handler.codec.MessageToMessageDecoder 源码实例Demo

下面列出了怎么用 io.netty.handler.codec.MessageToMessageDecoder 的API类实例代码及写法,或者点击链接到github查看源代码。


private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
    boolean needsCompress = false;
    if (!handledCompression
            && ctx.pipeline().names().indexOf("compression-encoder") > ctx.pipeline().names().indexOf("via-encoder")) {
        // Need to decompress this packet due to bad order
        ByteBuf decompressed = (ByteBuf) PipelineUtil.callDecode((MessageToMessageDecoder<?>) ctx.pipeline().get("compression-decoder"), ctx, buf).get(0);
        try {
            buf.clear().writeBytes(decompressed);
        } finally {
            decompressed.release();
        }
        ChannelHandler encoder = ctx.pipeline().get("via-encoder");
        ChannelHandler decoder = ctx.pipeline().get("via-decoder");
        ctx.pipeline().remove(encoder);
        ctx.pipeline().remove(decoder);
        ctx.pipeline().addAfter("compression-encoder", "via-encoder", encoder);
        ctx.pipeline().addAfter("compression-decoder", "via-decoder", decoder);
        needsCompress = true;
        handledCompression = true;
    }
    return needsCompress;
}
 
源代码2 项目: ViaVersion   文件: BungeePipelineUtil.java

public static List<Object> callDecode(MessageToMessageDecoder decoder, ChannelHandlerContext ctx, ByteBuf input) throws InvocationTargetException {
    List<Object> output = new ArrayList<>();
    try {
        BungeePipelineUtil.DECODE_METHOD.invoke(decoder, ctx, input, output);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return output;
}
 
源代码3 项目: ViaVersion   文件: BungeePipelineUtil.java

public static ByteBuf decompress(ChannelHandlerContext ctx, ByteBuf bytebuf) {
    try {
        return (ByteBuf) callDecode((MessageToMessageDecoder) ctx.pipeline().get("decompress"), ctx.pipeline().context("decompress"), bytebuf).get(0);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        return ctx.alloc().buffer();
    }
}
 
源代码4 项目: ViaVersion   文件: PipelineUtil.java

public static List<Object> callDecode(MessageToMessageDecoder decoder, ChannelHandlerContext ctx, Object msg) throws InvocationTargetException {
    List<Object> output = new ArrayList<>();
    try {
        MTM_DECODE.invoke(decoder, ctx, msg, output);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return output;
}
 
 类所在包
 类方法
 同包方法