当前位置: 首页>>代码示例>>Java>>正文


Java ByteToMessageDecoder类代码示例

本文整理汇总了Java中io.netty.handler.codec.ByteToMessageDecoder的典型用法代码示例。如果您正苦于以下问题:Java ByteToMessageDecoder类的具体用法?Java ByteToMessageDecoder怎么用?Java ByteToMessageDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ByteToMessageDecoder类属于io.netty.handler.codec包,在下文中一共展示了ByteToMessageDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initChannel

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
    UserConnection info = new UserConnection(socketChannel);
    // init protocol
    new ProtocolPipeline(info);
    // Add originals
    this.method.invoke(this.original, socketChannel);

    HandlerConstructor constructor = ClassGenerator.getConstructor();
    // Add our transformers
    MessageToByteEncoder encoder = constructor.newEncodeHandler(info, (MessageToByteEncoder) socketChannel.pipeline().get("encoder"));
    ByteToMessageDecoder decoder = constructor.newDecodeHandler(info, (ByteToMessageDecoder) socketChannel.pipeline().get("decoder"));
    BukkitPacketHandler chunkHandler = new BukkitPacketHandler(info);

    socketChannel.pipeline().replace("encoder", "encoder", encoder);
    socketChannel.pipeline().replace("decoder", "decoder", decoder);
    socketChannel.pipeline().addAfter("packet_handler", "viaversion_packet_handler", chunkHandler);
}
 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:19,代码来源:BukkitChannelInitializer.java

示例2: initChannel

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
    // Ensure ViaVersion is loaded
    if (ProtocolRegistry.SERVER_PROTOCOL != -1) {
        UserConnection info = new UserConnection(socketChannel);
        // init protocol
        new ProtocolPipeline(info);
        // Add originals
        this.method.invoke(this.original, socketChannel);
        // Add our transformers
        MessageToByteEncoder encoder = new SpongeEncodeHandler(info, (MessageToByteEncoder) socketChannel.pipeline().get("encoder"));
        ByteToMessageDecoder decoder = new SpongeDecodeHandler(info, (ByteToMessageDecoder) socketChannel.pipeline().get("decoder"));
        SpongePacketHandler chunkHandler = new SpongePacketHandler(info);

        socketChannel.pipeline().replace("encoder", "encoder", encoder);
        socketChannel.pipeline().replace("decoder", "decoder", decoder);
        socketChannel.pipeline().addAfter("packet_handler", "viaversion_packet_handler", chunkHandler);
    } else {
        this.method.invoke(this.original, socketChannel);
    }
}
 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:22,代码来源:SpongeChannelInitializer.java

示例3: autoAddHttpExtractor

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
static void autoAddHttpExtractor(NettyContext c, String name, ChannelHandler
		handler){

	if (handler instanceof ByteToMessageDecoder
			|| handler instanceof ByteToMessageCodec
			|| handler instanceof CombinedChannelDuplexHandler) {
		String extractorName = name+"$extractor";

		if(c.channel().pipeline().context(extractorName) != null){
			return;
		}

		c.channel().pipeline().addBefore(name, extractorName, HTTP_EXTRACTOR);

		if(NettyContext.isPersistent(c.channel())){
			c.onClose(() -> c.removeHandler(extractorName));
		}

	}
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:21,代码来源:HttpOperations.java

示例4: newSslInitiator

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
ChannelHandler newSslInitiator() {
    return new ByteToMessageDecoder() {
        @Override
        protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
            if(in.readableBytes() < 1) {
                return;
            }
            if('S' != in.readByte()) {
                ctx.fireExceptionCaught(new IllegalStateException("SSL required but not supported by backend server"));
                return;
            }
            ctx.pipeline().remove(this);
            ctx.pipeline().addFirst(
                    SslContextBuilder
                            .forClient()
                            .trustManager(InsecureTrustManagerFactory.INSTANCE)
                            .build()
                            .newHandler(ctx.alloc()));
        }
    };
}
 
开发者ID:alaisi,项目名称:postgres-async-driver,代码行数:22,代码来源:NettyPgProtocolStream.java

示例5: createFrameDecoder

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
/**
 * Creates a LengthFieldBasedFrameDecoder where the first 8 bytes are the length of the frame.
 * This is used before all decoders.
 */
public static ByteToMessageDecoder createFrameDecoder() {
  // maxFrameLength = 2G
  // lengthFieldOffset = 0
  // lengthFieldLength = 8
  // lengthAdjustment = -8, i.e. exclude the 8 byte length itself
  // initialBytesToStrip = 8, i.e. strip out the length field itself
  return new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 8, -8, 8);
}
 
开发者ID:Tencent,项目名称:angel,代码行数:13,代码来源:NettyUtils.java

示例6: initChannel

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
    ch.pipeline().addLast("openChannels", transport.serverOpenChannels);
    final HttpRequestDecoder decoder = new HttpRequestDecoder(
        Math.toIntExact(transport.maxInitialLineLength.getBytes()),
        Math.toIntExact(transport.maxHeaderSize.getBytes()),
        Math.toIntExact(transport.maxChunkSize.getBytes()));
    decoder.setCumulator(ByteToMessageDecoder.COMPOSITE_CUMULATOR);
    ch.pipeline().addLast("decoder", decoder);
    ch.pipeline().addLast("decoder_compress", new HttpContentDecompressor());
    ch.pipeline().addLast("encoder", new HttpResponseEncoder());
    final HttpObjectAggregator aggregator = new HttpObjectAggregator(Math.toIntExact(transport.maxContentLength.getBytes()));
    if (transport.maxCompositeBufferComponents != -1) {
        aggregator.setMaxCumulationBufferComponents(transport.maxCompositeBufferComponents);
    }
    ch.pipeline().addLast("aggregator", aggregator);
    if (transport.compression) {
        ch.pipeline().addLast("encoder_compress", new HttpContentCompressor(transport.compressionLevel));
    }
    if (SETTING_CORS_ENABLED.get(transport.settings())) {
        ch.pipeline().addLast("cors", new Netty4CorsHandler(transport.getCorsConfig()));
    }
    if (transport.pipelining) {
        ch.pipeline().addLast("pipelining", new HttpPipeliningHandler(transport.pipeliningMaxEvents));
    }
    ch.pipeline().addLast("handler", requestHandler);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:Netty4HttpServerTransport.java

示例7: callDecode

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
/**
 * Call the decode method on a netty ByteToMessageDecoder
 *
 * @param decoder The decoder
 * @param ctx     The current context
 * @param input   The packet to decode
 * @return A list of the decoders output
 * @throws InvocationTargetException If an exception happens while executing
 */
public static List<Object> callDecode(ByteToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws InvocationTargetException {
    List<Object> output = new ArrayList<>();
    try {
        PipelineUtil.DECODE_METHOD.invoke(decoder, ctx, input, output);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return output;
}
 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:19,代码来源:PipelineUtil.java

示例8: getDecoder

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
public ByteToMessageDecoder getDecoder() {
    ByteDecoder decoder = new ByteDecoder();
    decoder.setMessageCodec(msgCodec);
    decoder.setHeadCodec(headCodec);
    return decoder;
}
 
开发者ID:wangchongjie,项目名称:multi-engine,代码行数:8,代码来源:DefaultByteCodecFactory.java

示例9: initChannel

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
protected void initChannel(final Channel channel) throws Exception
{
    super.initChannel(channel);
    channel.pipeline().addFirst("sslDetectionHandler", new ByteToMessageDecoder()
    {
        @Override
        protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception
        {
            if (byteBuf.readableBytes() < 5)
            {
                // To detect if SSL must be used we need to have at least 5 bytes, so return here and try again
                // once more bytes a ready.
                return;
            }
            if (SslHandler.isEncrypted(byteBuf))
            {
                // Connection uses SSL/TLS, replace the detection handler with a SslHandler and so use
                // encryption.
                SslHandler sslHandler = createSslHandler();
                channelHandlerContext.pipeline().replace(this, "ssl", sslHandler);
            }
            else
            {
                // Connection use no TLS/SSL encryption, just remove the detection handler and continue without
                // SslHandler in the pipeline.
                channelHandlerContext.pipeline().remove(this);
            }
        }
    });
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:31,代码来源:Server.java

示例10: initChannel

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {

    // Initialize our session Object when the channel is initialized, attach
    // it to the channel.
    ch.attr(NetworkConstants.SESSION_KEY).setIfAbsent(new PlayerIO(ch));

    // Initialize the pipeline channel handlers.
    ChannelDuplexHandler timeout = new IdleStateHandler(NetworkConstants.INPUT_TIMEOUT, 0, 0);
    ByteToMessageDecoder loginHandshakeHandler = new LoginHandshakeHandler();

    ch.pipeline().addLast("login-handshake", loginHandshakeHandler);
    ch.pipeline().addLast("channel-handler", channelHandler);
    ch.pipeline().addLast("timeout", timeout);
}
 
开发者ID:lare96,项目名称:asteria-3.0,代码行数:16,代码来源:NetworkChannelInitializer.java

示例11: newDecodeHandler

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
public BukkitDecodeHandler newDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {
    return new BukkitDecodeHandler(info, minecraftDecoder);
}
 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:5,代码来源:BasicHandlerConstructor.java

示例12: BukkitDecodeHandler

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
public BukkitDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {
    this.info = info;
    this.minecraftDecoder = minecraftDecoder;
}
 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:5,代码来源:BukkitDecodeHandler.java

示例13: SpongeDecodeHandler

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
public SpongeDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {
    this.info = info;
    this.minecraftDecoder = minecraftDecoder;
}
 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:5,代码来源:SpongeDecodeHandler.java

示例14: getDecoder

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
/**
 * 获取解码器 @see ByteToMessageDecoder
 * 
 * @return 解码器
 */
ByteToMessageDecoder getDecoder();
 
开发者ID:wangchongjie,项目名称:multi-engine,代码行数:7,代码来源:ByteCodecFactory.java

示例15: newDecodeHandler

import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
public ByteToMessageDecoder newDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder); 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:2,代码来源:HandlerConstructor.java


注:本文中的io.netty.handler.codec.ByteToMessageDecoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。