package speiger.src.coreengine.assets.impl.parsers;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;

import org.lwjgl.system.MemoryUtil;

import speiger.src.coreengine.assets.api.IAssetParser;

public class Buffers {
	public static final IAssetParser<ByteBuffer> HEAP = new Heap();
	public static final IAssetParser<ByteBuffer> DIRECT = new Direct();
	
	public static class Heap implements IAssetParser<ByteBuffer> {
		@Override
		public ByteBuffer parse(Path path) throws IOException {
			return ByteBuffer.wrap(Files.readAllBytes(path));
		}
	}
	
	public static class Direct implements IAssetParser<ByteBuffer> {
		@Override
		public ByteBuffer parse(Path path) throws IOException {
			byte[] data = Files.readAllBytes(path);
			ByteBuffer buffer = MemoryUtil.memAlloc(data.length);
			buffer.put(data);
			buffer.flip();
			return buffer;
		}
	}
}
