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


Java MessageToByteEncoder类代码示例

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


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

示例1: AbstractNetTcp

import io.netty.handler.codec.MessageToByteEncoder; //导入依赖的package包/类
protected AbstractNetTcp(DataManager data, MessageReceivedListener listener, String netName){
	super(data, netName);
	initializer = new ChannelInitializer<SocketChannel>() {
		@Override
		protected void initChannel(SocketChannel ch) throws Exception {
			ch.pipeline().addLast("encoder", new MessageToByteEncoder<byte[]>() {
				@Override
				protected void encode(ChannelHandlerContext ctx, byte[] msg, ByteBuf out) throws Exception {
					out.writeBytes(msg);
				}
			});
			ch.pipeline().addLast("handler", new TCPHandler(data, listener));
		}
	};
	this.data = data;
}
 
开发者ID:okou19900722,项目名称:lippen-network-tool,代码行数:17,代码来源:AbstractNetTcp.java

示例2: initChannel

import io.netty.handler.codec.MessageToByteEncoder; //导入依赖的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

示例3: initChannel

import io.netty.handler.codec.MessageToByteEncoder; //导入依赖的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

示例4: callEncode

import io.netty.handler.codec.MessageToByteEncoder; //导入依赖的package包/类
public static ByteBuf callEncode(MessageToByteEncoder encoder, ChannelHandlerContext ctx, ByteBuf input) throws InvocationTargetException {
    ByteBuf output = ctx.alloc().buffer();
    try {
        BungeePipelineUtil.ENCODE_METHOD.invoke(encoder, ctx, input, output);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return output;
}
 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:10,代码来源:BungeePipelineUtil.java

示例5: compress

import io.netty.handler.codec.MessageToByteEncoder; //导入依赖的package包/类
public static ByteBuf compress(ChannelHandlerContext ctx, ByteBuf bytebuf) {
    try {
        return callEncode((MessageToByteEncoder) ctx.pipeline().get("compress"), ctx.pipeline().context("compress"), bytebuf);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        return ctx.alloc().buffer();
    }
}
 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:9,代码来源:BungeePipelineUtil.java

示例6: getEncoder

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

示例7: beginEncode

import io.netty.handler.codec.MessageToByteEncoder; //导入依赖的package包/类
@Override
protected Result beginEncode(HttpResponse headers, String acceptEncoding) {
    return new Result("test", new EmbeddedChannel(new MessageToByteEncoder<ByteBuf>() {
        @Override
        protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
            out.writeBytes(String.valueOf(in.readableBytes()).getBytes(CharsetUtil.US_ASCII));
            in.skipBytes(in.readableBytes());
        }
    }));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:11,代码来源:HttpContentEncoderTest.java

示例8: newEncoder

import io.netty.handler.codec.MessageToByteEncoder; //导入依赖的package包/类
@Override
public ChannelOutboundHandler newEncoder() {
	return new MessageToByteEncoder<byte[]>() {

		@Override
		protected void encode(ChannelHandlerContext ctx, byte[] msg,
				ByteBuf out) throws Exception {
			out.writeBytes(msg);
		}
		
	};
}
 
开发者ID:leo27lijiang,项目名称:remote-netty,代码行数:13,代码来源:FileServer.java

示例9: newEncoder

import io.netty.handler.codec.MessageToByteEncoder; //导入依赖的package包/类
@Override
public ChannelOutboundHandler newEncoder() {
	return new MessageToByteEncoder<ByteBean>() {

		@Override
		protected void encode(ChannelHandlerContext ctx, ByteBean msg,
				ByteBuf out) throws Exception {
			out.writeBytes(msg.getContent(), msg.getPosition(), msg.getLength());
		}
		
	};
}
 
开发者ID:leo27lijiang,项目名称:remote-netty,代码行数:13,代码来源:FileClient.java

示例10: beginEncode

import io.netty.handler.codec.MessageToByteEncoder; //导入依赖的package包/类
@Override
protected Result beginEncode(HttpResponse headers, CharSequence acceptEncoding) {
    return new Result("test", new EmbeddedChannel(new MessageToByteEncoder<ByteBuf>() {
        @Override
        protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
            out.writeBytes(String.valueOf(in.readableBytes()).getBytes(CharsetUtil.US_ASCII));
            in.skipBytes(in.readableBytes());
        }
    }));
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:11,代码来源:HttpContentEncoderTest.java

示例11: newEncodeHandler

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

示例12: BukkitEncodeHandler

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

示例13: SpongeEncodeHandler

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

示例14: callEncode

import io.netty.handler.codec.MessageToByteEncoder; //导入依赖的package包/类
/**
 * Call the encode method on a netty MessageToByteEncoder
 *
 * @param encoder The encoder
 * @param ctx     The current context
 * @param msg     The packet to encode
 * @param output  The bytebuf to write the output to
 * @throws InvocationTargetException If an exception happens while executing
 */
public static void callEncode(MessageToByteEncoder encoder, ChannelHandlerContext ctx, Object msg, ByteBuf output) throws InvocationTargetException {
    try {
        PipelineUtil.ENCODE_METHOD.invoke(encoder, ctx, msg, output);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:17,代码来源:PipelineUtil.java

示例15: getEncoder

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


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