I produce some data in C++ that I want to access in a Python program. I have figured out how to serialize/deserialize to/from a binary file with boost in C++, but not how to access the data in Python (without manually parsing the binary file).
Here is my C++ code for serialization:
/* Save some data to binary file */
template <typename T>
int serializeToBinaryFile( const char* filename, const T& someValue,
const vector<T>& someVector )
{
ofstream file( filename, ios::out | ios::binary | ios::trunc );
if ( file.is_open() )
{
boost::archive::text_oarchive oa(file);
int sizeOfDataType = sizeof(T);
oa & sizeOfDataType;
oa & someValue;
oa & someVector;
file.close();
return 0;
} else {
return 1;
}
}
Here is my C++ code for deserialization:
/* Load some data from binary file */
template <typename T>
int deSerializeFromBinaryFile( const char* filename, int& sizeOfDataType,
T& someValue, vector<T>& someVector )
{
ifstream file( filename, ios::in | ios::binary );
if ( file.is_open() )
{
boost::archive::text_iarchive ia(file);
ia & sizeOfDataType;
ia & someValue;
ia & someVector;
file.close();
return 0;
} else {
return 1;
}
}
How can I load the value and vector to objects in a Python program?