private static List <T> Collect <T>(EndianBinaryReader stream, LoadTypeFromStream <T> function, int count) { List <T> values = new List <T>(); for (int i = 0; i < count; i++) { values.Add(function(stream)); } return(values); }
// This version of the function just skips to the specific entry and loads one of them. More useful than trying to read the data into a list and then getting the entry // from the list. private static T ReadEntry <T>(EndianBinaryReader stream, LoadTypeFromStream <T> readFunction, long chunkStart, int[] offsets, int offset, int entryNumber, int itemSize) { if (offsets[offset] == 0) { return(default(T)); } long streamPos = stream.BaseStream.Position; stream.BaseStream.Position = (chunkStart + offsets[offset]) + (entryNumber * itemSize); T val = readFunction(stream); stream.BaseStream.Position = streamPos; return(val); }
private static List <T> ReadSection <T>(EndianBinaryReader stream, long chunkStart, int chunkSize, int[] offsets, int offset, LoadTypeFromStream <T> function, int itemSize) { // If there's none of this value, early out and return an empty list, otherwise it parses // everything from the chunk start up to the next one as the requested section. if (offsets[offset] == 0) { return(new List <T>()); } stream.BaseStream.Position = chunkStart + offsets[offset]; return(Collect <T>(stream, function, GetOffsetLength(offsets, offset, chunkSize) / itemSize)); }