I am writing a file structure for our game we are making. I have ran into an issue with FileManager’s CreateFileReader and the issue is the file structure I have needs both support for read/write methods. Only issue that I am having is that I am getting a InPos <= Size error that is called in Seek the check call, which is causing problems.
Let me explain what I have so far:
I am creating a Data Object Database structure that acts much like a book. Each “Page” which is an Index Block, contains 50 “Data Blocks” per “Index Block” up to 50 before it makes another page.
When I am creating the database for the first time, I have no problem when it comes to seeking bytes for example.
Header is 100 bytes, regardless of what is written it reserves 100 bytes always.
That means perhaps only 58 bytes are written but when I seek to 100 it will push the buffer to that position, which is intentional. When I then write the first Page which is empty and contains no data blocks.
When I go and write a data block I get a big issue because each Index Block and Data Block contains a MAXIMUM of 4096 bytes in size. Once the database is created it will then Open the stream for reading purposes after closing it aka when creating an empty database for the first time.
I read the header which seeks at 0, and then the index page 0 which is offset at 100 bytes to read the first ‘page’. Now as expected the database loads fine. As soon as I go to write a datablock it offsets based on this amount.
Remember that the CreateFileReader is now the FArchive purpose using GenericReader
HEADER_SIZE + (blockId * BLOCK_SIZE) + (IndexBlockHeaderSize + (IndexesPerBlock * IndexBlockSizePerEntry));
100 + (0) + (46 + (50 * 81)) = 4196 to Seek for.
InPos = 4196
Size = 188 bytes
check(InPos <= Size)
Therefore now what can I do to make this work correctly? Would I need to create my own FArchive to where it supports both “Read” and “Write” along with Seek?