2.9 Creating architecture-independent file formats

libbinio does not inherently support any specific file format. This is considered a feature, as it also does not impose any file format upon the user.

It is, however, very easy to create your own architecture-independent file format or enhance a file format to make it architecture-independent on top of libbinio, by creating wrapper classes that you use to access your streams.

Here is an example that inserts a two byte header in front of your file format to make it architecture-independent:

class myifstream: public binifstream
{
public:
  void open(const char *filename, const Mode mode = NoCreate)
  {
    binifstream::open(filename, mode);

    setFlag(binio::BigEndian, getByte());
    setFlag(binio::FloatIEEE, getByte());
  }
};

class myofstream: public binofstream
{
public:
  void open(const char *filename, const Mode mode = NoCreate)
  {
    binofstream::open(filename, mode);

    putByte(getFlag(binio::BigEndian));
    putByte(getFlag(binio::FloatIEEE));
  }
};

You can use these new classes as usual.