Signature of files saved by boost::serialization
Dear list, What would be a good way to tell if a file is saved by boost::serialization? I notice that the first several characters of binary_oarchive saved files are "\026 \0 \0 \0 \0 \0 \0 serialization" and are "22 serialization" for text_oarchive saved files. Are they reliable signatures? Many thanks in advance. Bo
I think the most practical way would be to try to create and archive with the "suspect" stream. construction of an archive from a stream reads the serialization header. If the header doesn't contain what is expected - I think an exception is thrown. Now that I read the above, it makes me wonder if that's a good idea - but there it is. Robert Ramey Bo Peng wrote:
Dear list,
What would be a good way to tell if a file is saved by boost::serialization? I notice that the first several characters of binary_oarchive saved files are "\026 \0 \0 \0 \0 \0 \0 serialization" and are "22 serialization" for text_oarchive saved files. Are they reliable signatures?
Many thanks in advance. Bo
I think the most practical way would be to try to create and archive with the "suspect" stream.
I am not quite sure what you mean since the files are written by text_oarchive etc, and should be read by corresponding streams such as text_iarchive. I do not know how to write some type information at the beginning of the files and use a general iarchive to read it first.
construction of an archive from a stream reads the serialization header. If the header doesn't contain what is expected - I think an exception is thrown.
This is what I am doing: try to guess the file type by file extension. If fails, use try/catch to read the file using different iarchive objects. I think it would be better to judge the file type by file header. Bo
Bo Peng wrote:
I do not know how to write some type information at the beginning of the files and use a general iarchive to read it first.
the serialization library itself writes header information (unless opened with "no_header") itself. It also checks for the existence of this information (unless opened with "no_header") so you don't have to do anything otehr than catch the exception.
This is what I am doing: try to guess the file type by file extension. If fails, use try/catch to read the file using different iarchive objects. I think it would be better to judge the file type by file header.
If you want to do that you'll have to look into the library code to see how the headers are made and checked. But copying this code into your app would be exactly equivalent to creating the archive and catching the exception if it fails Robert Ramey
Bo
participants (2)
-
Bo Peng
-
Robert Ramey