How do you lay out your binary file format?

Each application has its own binary file format (for example, .mpq, .wad). In addition, he was usually zipped.

So my question is: how do you skillfully / skillfully decompose the binary contents of your file. Do you have a table of contents like structure at the beginning? Are you better off dumping everything in one file?

Let's say you have an array of Shapes , and each Shape has warped vertex data (therefore, the vertex data was modified from the file from which it was originally loaded, so it must be saved again).

 class Shape { vector<Vertex> verts ; } ; class Sphere : public Shape { } ; // ...more geometric shapes (Tet, Cube) are defined.. class Model : public Shape { } ; // general model "Shape" loaded from file vector<Shape*> shapes ; // save me! contents are mix of Model, Sphere, Tet.. // each with variable number of verts 
+6
source share
2 answers

My favorite article on file formats is at http://www.fadden.com/techmisc/file-formats.htm .

In addition, it probably depends on what data you store and how this data will be used (will it be transmitted over the network, first of all, how important is the search engine? Etc ...).

Start with this article; this can help crystallize your thoughts if you already have a format that needs to be developed.

+6
source

In short, if you only need serialization, which means that you will read and write from and to stream than you can use here without any problems and release a member of your group by elements or use any serialization library from CArchive to .. .. everything you see.

If not, and you will need to directly access your data inside the file, then ... you will use your requirements, and they will tell you with some skill what format the file that you use having will be.

And yes, to a broad topic, to live here. For instance,

I need a thumbnail database for my software. Each sketch has a timestamp, and I know that they will have a different size. Requirements:

  • sequential write (thumbs will be added to the end of the database)
  • thumbs will be added in ascending order.
  • direct reading (set time, getting sketch in o (1))
  • without further database modification
  • thumbnails will be on for 15 seconds

Yes, the requirements are simple, but they stand for themselves.

I created two files, one with indexes and the other with images.

Storage: add the data file with the image, add the index file with the image index to the data file. Reading: find the index in the file using simple indexing (index (timestamp-timestamp_start)/15 ). Use this index to retrieve image data.

+1
source

Source: https://habr.com/ru/post/898491/


All Articles