class KvStateRequestSerializer {

	public static <K, N> Tuple2<K, N> deserializeKeyAndNamespace(
			byte[] serializedKeyAndNamespace,
			TypeSerializer<K> keySerializer,
			TypeSerializer<N> namespaceSerializer) throws IOException {

		DataInputDeserializer dis = new DataInputDeserializer(
				serializedKeyAndNamespace,
				0,
				serializedKeyAndNamespace.length);

		try {
			K key = keySerializer.deserialize(dis);
			byte magicNumber = dis.readByte();
			if (magicNumber != 42) {
				throw new IOException("Unexpected magic number " + magicNumber + ".");
			}
			N namespace = namespaceSerializer.deserialize(dis);

			if (dis.available() > 0) {
				throw new IOException("Unconsumed bytes in the serialized key and namespace.");
			}

			return new Tuple2<>(key, namespace);
		} catch (IOException e) {
			throw new IOException("Unable to deserialize key " +
				"and namespace. This indicates a mismatch in the key/namespace " +
				"serializers used by the KvState instance and this access.", e);
		}
	}

}