ScummVM API documentation
Common::Serializer Class Reference

#include <serializer.h>

Inheritance diagram for Common::Serializer:
MM::Xeen::XeenSerializer Stark::ResourceSerializer TsAGE::Serializer

Public Types

typedef uint32 Version
 

Public Member Functions

 Serializer (SeekableReadStream *in, WriteStream *out)
 
bool isSaving ()
 
bool isLoading ()
 
template<typename T >
void syncAsByte (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsSByte (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsUint16LE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsUint16BE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsSint16LE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsSint16BE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsUint32LE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsUint32BE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsSint32LE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsSint32BE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsFloatLE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsFloatBE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsDoubleLE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncAsDoubleBE (T &val, Version minVersion=0, Version maxVersion=kLastVersion)
 
bool err () const
 
void clearErr ()
 
bool syncVersion (Version currentVersion)
 
Version getVersion () const
 
void setVersion (Version version)
 
uint bytesSynced () const
 
void skip (uint32 size, Version minVersion=0, Version maxVersion=kLastVersion)
 
void syncBytes (byte *buf, uint32 size, Version minVersion=0, Version maxVersion=kLastVersion)
 
bool matchBytes (const char *magic, byte size, Version minVersion=0, Version maxVersion=kLastVersion)
 
void syncString (String &str, Version minVersion=0, Version maxVersion=kLastVersion)
 
void syncString32 (U32String &str, Version minVersion=0, Version maxVersion=kLastVersion)
 
template<typename T >
void syncArray (T *arr, size_t entries, void(*serializer)(Serializer &, T &), Version minVersion=0, Version maxVersion=kLastVersion)
 

Static Public Member Functions

template<typename T >
static void Uint32LE (Serializer &s, T &value)
 
template<typename T >
static void Uint32BE (Serializer &s, T &value)
 
template<typename T >
static void Sint32LE (Serializer &s, T &value)
 
template<typename T >
static void Sint32BE (Serializer &s, T &value)
 
template<typename T >
static void FloatLE (Serializer &s, T &value)
 
template<typename T >
static void FloatBE (Serializer &s, T &value)
 
template<typename T >
static void DoubleLE (Serializer &s, T &value)
 
template<typename T >
static void DoubleBE (Serializer &s, T &value)
 
template<typename T >
static void Uint16LE (Serializer &s, T &value)
 
template<typename T >
static void Uint16BE (Serializer &s, T &value)
 
template<typename T >
static void Sint16LE (Serializer &s, T &value)
 
template<typename T >
static void Sint16BE (Serializer &s, T &value)
 
template<typename T >
static void Byte (Serializer &s, T &value)
 
template<typename T >
static void SByte (Serializer &s, T &value)
 

Static Public Attributes

static const Version kLastVersion = 0xFFFFFFFF
 

Protected Attributes

SeekableReadStream_loadStream
 
WriteStream_saveStream
 
uint _bytesSynced
 
Version _version
 

Detailed Description

This class allows syncing / serializing data (primarily game savestates) between memory and Read/WriteStreams. It optionally supports versioning the serialized data (client code must use the syncVersion() method for this). This makes it possible to support multiple versions of a savegame format with a single codepath

This class was heavily inspired by the save/load code in the SCUMM engine.

Member Function Documentation

◆ err()

bool Common::Serializer::err ( ) const
inline

Returns true if an I/O failure occurred. This flag is never cleared automatically. In order to clear it, client code has to call clearErr() explicitly.

◆ clearErr()

void Common::Serializer::clearErr ( )
inline

Reset the I/O error status as returned by err().

◆ syncVersion()

bool Common::Serializer::syncVersion ( Version  currentVersion)
inline

Sync the "version" of the savegame we are loading/creating.

Parameters
currentVersioncurrent format version, used when writing a new file
Returns
true if the version of the savestate is not too new.

◆ getVersion()

Version Common::Serializer::getVersion ( ) const
inline

Return the version of the savestate being serialized. Useful if the engine needs to perform additional adjustments when loading old savestates.

◆ setVersion()

void Common::Serializer::setVersion ( Version  version)
inline

Manually set the version

◆ bytesSynced()

uint Common::Serializer::bytesSynced ( ) const
inline

Return the total number of bytes synced so far.

◆ skip()

void Common::Serializer::skip ( uint32  size,
Version  minVersion = 0,
Version  maxVersion = kLastVersion 
)
inline

Skip a number of bytes in the data stream. This is useful to skip obsolete fields in old savestates.

◆ syncBytes()

void Common::Serializer::syncBytes ( byte *  buf,
uint32  size,
Version  minVersion = 0,
Version  maxVersion = kLastVersion 
)
inline

Sync a block of arbitrary fixed-length data.

◆ matchBytes()

bool Common::Serializer::matchBytes ( const char *  magic,
byte  size,
Version  minVersion = 0,
Version  maxVersion = kLastVersion 
)
inline

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'.

Parameters
magicmagic id as a byte sequence
sizelength of the magic id in bytes
Returns
true if the magic id matched, false otherwise

◆ syncString()

void Common::Serializer::syncString ( String str,
Version  minVersion = 0,
Version  maxVersion = kLastVersion 
)
inline

Sync a C-string, by treating it as a zero-terminated byte sequence.

◆ syncString32()

void Common::Serializer::syncString32 ( U32String str,
Version  minVersion = 0,
Version  maxVersion = kLastVersion 
)
inline

Sync a U32-string


The documentation for this class was generated from the following file: