I am using binary file for storing measured data of some product. The product was the only one type before, now I have to be able to save/load more types of product.
I'm going to save some type descriptor at the beginning of the file, 1 Byte should be absolutely enough, there will be only a few types (2, maybe 3 or 4 in future).
The problem is, that I still need to be able load old binary files without this descriptor. Here is my old code with commentary where I want to check presence of descriptor and afterwards make a decision about product type like this:
- No descriptor -> old product
- Descriptor = xxx -> new product xxx
Is it possible to save descriptor in such a format? I guess the calling reader.PeekChar() is only one possibility because of not moving to next bytes, but I'm not sure how to use it in this case.
BinaryReader reader;
using (reader = new BinaryReader(File.Open(header.path, FileMode.Open, FileAccess.Read)))
{
// ...
// check presence of product type descriptor
// make a decision of type
// ...
DateTime measTime = DateTime.FromOADate(reader.ReadDouble());
double diameter = reader.ReadDouble();
double plusToler = reader.ReadDouble();
double minusToler = reader.ReadDouble();
}