本文整理匯總了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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例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());
}
}));
}
示例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);
}
};
}
示例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());
}
};
}
示例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());
}
}));
}
示例11: newEncodeHandler
import io.netty.handler.codec.MessageToByteEncoder; //導入依賴的package包/類
@Override
public BukkitEncodeHandler newEncodeHandler(UserConnection info, MessageToByteEncoder minecraftEncoder) {
return new BukkitEncodeHandler(info, minecraftEncoder);
}
示例12: BukkitEncodeHandler
import io.netty.handler.codec.MessageToByteEncoder; //導入依賴的package包/類
public BukkitEncodeHandler(UserConnection info, MessageToByteEncoder minecraftEncoder) {
this.info = info;
this.minecraftEncoder = minecraftEncoder;
}
示例13: SpongeEncodeHandler
import io.netty.handler.codec.MessageToByteEncoder; //導入依賴的package包/類
public SpongeEncodeHandler(UserConnection info, MessageToByteEncoder minecraftEncoder) {
this.info = info;
this.minecraftEncoder = minecraftEncoder;
}
示例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();
}
}
示例15: getEncoder
import io.netty.handler.codec.MessageToByteEncoder; //導入依賴的package包/類
/**
* 獲取編碼器 @see MessageToByteEncoder
*
* @return 編碼器
*/
MessageToByteEncoder<Object> getEncoder();