org.fz.nettyx.codec.StructCodec Maven / Gradle / Ivy
package org.fz.nettyx.codec;
import cn.hutool.core.util.TypeUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageCodec;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import lombok.Getter;
import org.fz.nettyx.serializer.struct.StructSerializer;
import java.lang.reflect.Type;
import java.util.List;
/**
* struct codec
* @author fengbinbin
* @version 1.0
* @since 2024/7/26 18:58
*/
@Getter
public abstract class StructCodec extends ByteToMessageCodec {
private static final InternalLogger log = InternalLoggerFactory.getInstance(StructCodec.class);
private static final boolean DEFAULT_SKIP_LEFT_BYTES = true;
private final Type type = TypeUtil.getTypeArgument(this.getClass());
private final boolean skipLeftBytes;
protected StructCodec() {
this.skipLeftBytes = DEFAULT_SKIP_LEFT_BYTES;
}
protected StructCodec(boolean skipLeftBytes) {
this.skipLeftBytes = skipLeftBytes;
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List