blob: e2c144e5a61817a64de05f341eb452a3fd630b2e [file] [log] [blame] [raw]
package protocolsupport.protocol.pipeline.version;
import java.util.List;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.DecoderException;
import protocolsupport.api.Connection;
import protocolsupport.protocol.packet.middle.ServerBoundMiddlePacket;
import protocolsupport.protocol.serializer.ProtocolSupportPacketDataSerializer;
import protocolsupport.protocol.storage.NetworkDataCache;
import protocolsupport.zplatform.ServerPlatform;
public class AbstractModernWithoutReorderPacketDecoder extends AbstractPacketDecoder {
public AbstractModernWithoutReorderPacketDecoder(Connection connection, NetworkDataCache sharedstorage) {
super(connection, sharedstorage);
}
private final ProtocolSupportPacketDataSerializer serializer = new ProtocolSupportPacketDataSerializer(null, connection.getVersion());
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf input, List<Object> list) throws InstantiationException, IllegalAccessException {
if (!input.isReadable()) {
return;
}
serializer.setBuf(input);
ServerBoundMiddlePacket packetTransformer = registry.getTransformer(ServerPlatform.get().getMiscUtils().getNetworkStateFromChannel(ctx.channel()), serializer.readVarInt());
packetTransformer.readFromClientData(serializer);
if (serializer.isReadable()) {
throw new DecoderException("Did not read all data from packet " + packetTransformer.getClass().getName() + ", bytes left: " + serializer.readableBytes());
}
addPackets(packetTransformer.toNative(), list);
}
}