Skip to content

Commit

Permalink
[ISSUE #4677]netty codec enhancement (#4678)
Browse files Browse the repository at this point in the history
  • Loading branch information
karsonto authored Dec 22, 2023
1 parent e056d7a commit 2989941
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,37 @@

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageCodec;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.ReplayingDecoder;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.Preconditions;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Codec {
public class Codec extends ByteToMessageCodec<Package> {

private static final int FRAME_MAX_LENGTH = 1024 * 1024 * 4;

private static final byte[] CONSTANT_MAGIC_FLAG = serializeBytes("EventMesh");
private static final byte[] VERSION = serializeBytes("0000");

private Encoder encoder = new Encoder();
private Decoder decoder = new Decoder();

@Override
protected void encode(ChannelHandlerContext ctx, Package pkg, ByteBuf out) throws Exception {
encoder.encode(ctx, pkg, out);
}

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
decoder.decode(ctx, in, out);
}

public static class Encoder extends MessageToByteEncoder<Package> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected synchronized void open(SimpleChannelInboundHandler<Package> handler) t

@Override
public void initChannel(SocketChannel ch) {
ch.pipeline().addLast(new Codec.Encoder(), new Codec.Decoder())
ch.pipeline().addLast(new Codec())
.addLast(handler, newExceptionHandler());
}
});
Expand Down

0 comments on commit 2989941

Please sign in to comment.