aboutsummaryrefslogtreecommitdiff
path: root/common/serializer.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/serializer.h')
-rw-r--r--common/serializer.h57
1 files changed, 29 insertions, 28 deletions
diff --git a/common/serializer.h b/common/serializer.h
index a44883683b..013a91c0d2 100644
--- a/common/serializer.h
+++ b/common/serializer.h
@@ -127,34 +127,6 @@ public:
*/
Version getVersion() const { return _version; }
- /**
- * Sync a 'magic id' of up to 256 bytes, and return whether it matched.
- * When saving, this will simply write out the magic id and return true.
- * When loading, this will read the specified number of bytes, compare it
- * to the given magic id and return true on a match, false otherwise.
- *
- * A typical magic id is a FOURCC like 'MAGI'.
- *
- * @param magic magic id as a byte sequence
- * @param size length of the magic id in bytes
- * @return true if the magic id matched, false otherwise
- *
- * @todo Should this have minVersion/maxVersion params, too?
- */
- bool syncMagic(const char *magic, byte size) {
- char buf[256];
- bool match;
- if (isSaving()) {
- _saveStream->write(magic, size);
- match = true;
- } else {
- _loadStream->read(buf, size);
- match = (0 == memcmp(buf, magic, size));
- }
- _bytesSynced += size;
- return match;
- }
-
/**
* Return the total number of bytes synced so far.
@@ -193,6 +165,35 @@ public:
}
/**
+ * Sync a 'magic id' of up to 256 bytes, and return whether it matched.
+ * When saving, this will simply write out the magic id and return true.
+ * When loading, this will read the specified number of bytes, compare it
+ * to the given magic id and return true on a match, false otherwise.
+ *
+ * A typical magic id is a FOURCC like 'MAGI'.
+ *
+ * @param magic magic id as a byte sequence
+ * @param size length of the magic id in bytes
+ * @return true if the magic id matched, false otherwise
+ */
+ bool matchBytes(const char *magic, byte size, Version minVersion = 0, Version maxVersion = kLastVersion) {
+ if (_version < minVersion || _version > maxVersion)
+ return true; // Ignore anything which is not supposed to be present in this save game version
+
+ bool match;
+ if (isSaving()) {
+ _saveStream->write(magic, size);
+ match = true;
+ } else {
+ char buf[256];
+ _loadStream->read(buf, size);
+ match = (0 == memcmp(buf, magic, size));
+ }
+ _bytesSynced += size;
+ return match;
+ }
+
+ /**
* Sync a C-string, by treating it as a zero-terminated byte sequence.
* @todo Replace this method with a special Syncer class for Common::String
*/