package protocolsupport.protocol.utils;

import java.text.MessageFormat;
import java.util.EnumMap;
import java.util.Map;
import java.util.function.BiConsumer;

import io.netty.buffer.ByteBuf;
import protocolsupport.api.ProtocolVersion;

public class SimpleTypeSerializer<T> {

	protected final Map<ProtocolVersion, BiConsumer<ByteBuf, T>> entries = new EnumMap<>(ProtocolVersion.class);

	public BiConsumer<ByteBuf, T> get(ProtocolVersion version) {
		BiConsumer<ByteBuf, T> serializer = entries.get(version);
		if (serializer == null) {
			throw new IllegalArgumentException(MessageFormat.format("Don''t know how to serialize type for protocol version {0}", version));
		}
		return entries.get(version);
	}

	protected void register(BiConsumer<ByteBuf, T> serializer, ProtocolVersion... versions) {
		for (ProtocolVersion version : versions) {
			entries.put(version, serializer);
		}
	}

}

@@ -381,16 +381,407 @@
 lass);%0A%0A
+%09public SimpleTypeSerializer() %7B%0A%09%7D%0A%0A%09@SafeVarargs%0A%09public SimpleTypeSerializer(Map.Entry%3CBiConsumer%3CByteBuf, T%3E, ProtocolVersion%5B%5D%3E... entries) %7B%0A%09%09for (Map.Entry%3CBiConsumer%3CByteBuf, T%3E, ProtocolVersion%5B%5D%3E entry : entries) %7B%0A%09%09%09BiConsumer%3CByteBuf, T%3E serializer = entry.getKey();%0A%09%09%09for (ProtocolVersion version : entry.getValue()) %7B%0A%09%09%09%09this.entries.put(version, serializer);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A
 %09public 

Refactor SimpleTypeSerializer