All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.datasecs.hydra.shared.protocol.packets.serialization.PacketDecoder Maven / Gradle / Ivy

There is a newer version: 1.6.5
Show newest version
package de.datasecs.hydra.shared.protocol.packets.serialization;

import de.datasecs.hydra.shared.protocol.HydraProtocol;
import de.datasecs.hydra.shared.protocol.packets.Packet;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;

import java.util.List;

/**
 * Created with love by DataSecs on 29.09.2017.
 */
public class PacketDecoder extends MessageToMessageDecoder {

    private HydraProtocol protocol;

    public PacketDecoder(HydraProtocol protocol) {
        this.protocol = protocol;
    }

    @Override
    protected void decode(ChannelHandlerContext context, ByteBuf in, List out) throws Exception {
        in.readInt();

        Packet packet = protocol.createPacket(in.readByte());
        packet.setByteBuf(in);
        packet.read();

        out.add(packet);
    }
}