package edu.teco.dnd.network.codecs;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.socket.DatagramPacket;
import io.netty.handler.codec.MessageToMessageCodec;
import io.netty.util.AttributeKey;

import java.net.InetSocketAddress;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * A class that wraps ByteBufs into a DatagramPacket.
 * 
 * @author Philipp Adolf
 */
@Sharable
public class DatagramPacketWrapper extends MessageToMessageCodec<DatagramPacket, ByteBuf> {
	/**
	 * The logger for this class.
	 */
	private static final Logger LOGGER = LogManager.getLogger(DatagramPacketWrapper.class);

	/**
	 * The AttributeKey for the target address. The address must be attached to the context of this ChannelHandler.
	 */
	public static final AttributeKey<InetSocketAddress> TARGET_ADDRESS = AttributeKey.valueOf("targetAddress");

	@Override
	protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
		LOGGER.entry(ctx, msg, out);
		out.add(new DatagramPacket(msg.retain(), ctx.attr(TARGET_ADDRESS).get()));
		LOGGER.exit();
	}

	@Override
	protected void decode(ChannelHandlerContext ctx, DatagramPacket msg, List<Object> out) throws Exception {
		LOGGER.entry(ctx, msg, out);
		out.add(msg.content().retain());
		LOGGER.exit();
	}
}

@@ -465,23 +465,31 @@
 t wraps 
+%7B@link 
 ByteBuf
+%7D
 s into a
@@ -489,16 +489,23 @@
  into a 
+%7B@link 
 Datagram
@@ -514,38 +514,149 @@
 cket
-.%0A * %0A * @author Philipp Adolf
+%7Ds when sending and unwraps them when receiving. This%0A * handler needs to know the target address. It can be set via %7B@link #TARGET_ADDRESS%7D.
 %0A */
@@ -762,49 +762,8 @@
 %3E %7B%0A
-%09/**%0A%09 * The logger for this class.%0A%09 */%0A
 %09pri

Add JavaDoc for network.codecs package