factories.put(new Byte(key), factory);
}
public UpPacket read(ByteBuffer buffer) throws ProtocolException {
Byte key = new Byte(buffer.get());
PacketFactory factory = (PacketFactory) factories.get(key);
if (factory == null) throw new ProtocolException("No factory registered for " + key);
return factory.create(buffer.slice());
}