io.netty.handler.codec.MessageToMessageDecoder Java Examples

The following examples show how to use io.netty.handler.codec.MessageToMessageDecoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VelocityEncodeHandler.java    From ViaVersion with MIT License 6 votes vote down vote up
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;
}
 
Example #2
Source File: BungeePipelineUtil.java    From ViaVersion with MIT License 5 votes vote down vote up
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;
}
 
Example #3
Source File: BungeePipelineUtil.java    From ViaVersion with MIT License 5 votes vote down vote up
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();
    }
}
 
Example #4
Source File: PipelineUtil.java    From ViaVersion with MIT License 5 votes vote down vote up
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;
}