00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "torc/architecture/Versions.hpp"
00020 #include <iostream>
00021
00022 namespace torc {
00023 namespace architecture {
00024
00025 size_t Versions::readVersions(DigestStream& inStream, bool inShowVersion) {
00026
00027 size_t bytesReadOffset = inStream.getBytesRead();
00028 char scratch[1 << 10];
00029 uint16_t nameLength = 0;
00030
00031
00032 std::string torc("TORC");
00033 inStream.read(scratch, 4);
00034 scratch[4] = 0;
00035 if(!(torc == scratch)) {
00036 std::cerr << "This is not a valid Torc database. Magic \"" << scratch
00037 << "\" does not match expected \"" << torc << "\"." << std::endl;
00038 return 0;
00039 }
00040
00041
00042 inStream.read(mFormat.mMajor);
00043 inStream.read(mFormat.mMinor);
00044 inStream.read(mFormat.mRevision);
00045 inStream.read(mFormat.mReserved);
00046
00047 inStream.read(mBuild);
00048
00049
00050
00051
00052
00053 std::string versionHeader;
00054 inStream.readSectionHeader(versionHeader);
00055
00056 if(versionHeader != ">>>>Version >>>>") throw -1;
00057
00058
00059 inStream.read(mVendor.mMajor);
00060 inStream.read(mVendor.mMinor);
00061 inStream.read(mVendor.mRevision);
00062 inStream.read(mVendor.mReserved);
00063
00064 inStream.read(nameLength);
00065
00066 if(nameLength > sizeof(scratch)) throw -1;
00067 inStream.read(scratch, nameLength);
00068 scratch[nameLength] = 0;
00069 mVendorString = scratch;
00070
00071 if(inShowVersion) std::cout << "\tDatabase " << static_cast<uint32_t>(mFormat.mMajor)
00072 << "." << static_cast<uint32_t>(mFormat.mMinor) << "."
00073 << static_cast<uint32_t>(mFormat.mRevision) << " build " << mBuild << ", Vendor "
00074
00075
00076
00077 << '"' << mVendorString << '"' << std::endl;
00078
00079
00080 return inStream.getBytesRead() - bytesReadOffset;
00081 }
00082
00083 }
00084 }