Move SlRead/SlWrite functions to saveload.h

Add SlGetBytesRead and SlGetBytesWritten functions.
This commit is contained in:
Jonathan G Rennison
2015-08-01 12:20:28 +01:00
parent 4508cfbf93
commit a3980dc6ba
2 changed files with 62 additions and 39 deletions

View File

@@ -649,51 +649,24 @@ void SlWriteByte(byte b)
_sl.dumper->WriteByte(b); _sl.dumper->WriteByte(b);
} }
static inline int SlReadUint16() /**
* Returns number of bytes read so far
* May only be called during a load/load check action
*/
size_t SlGetBytesRead()
{ {
int x = SlReadByte() << 8; assert(_sl.action == SLA_LOAD || _sl.action == SLA_LOAD_CHECK);
return x | SlReadByte(); return _sl.reader->GetSize();
}
static inline uint32 SlReadUint32()
{
uint32 x = SlReadUint16() << 16;
return x | SlReadUint16();
}
static inline uint64 SlReadUint64()
{
uint32 x = SlReadUint32();
uint32 y = SlReadUint32();
return (uint64)x << 32 | y;
}
static inline void SlWriteUint16(uint16 v)
{
SlWriteByte(GB(v, 8, 8));
SlWriteByte(GB(v, 0, 8));
}
static inline void SlWriteUint32(uint32 v)
{
SlWriteUint16(GB(v, 16, 16));
SlWriteUint16(GB(v, 0, 16));
}
static inline void SlWriteUint64(uint64 x)
{
SlWriteUint32((uint32)(x >> 32));
SlWriteUint32((uint32)x);
} }
/** /**
* Read in bytes from the file/data structure but don't do * Returns number of bytes written so far
* anything with them, discarding them in effect * May only be called during a save action
* @param length The amount of bytes that is being treated this way
*/ */
static inline void SlSkipBytes(size_t length) size_t SlGetBytesWritten()
{ {
for (; length != 0; length--) SlReadByte(); assert(_sl.action == SLA_SAVE);
return _sl.dumper->GetSize();
} }
/** /**

View File

@@ -568,6 +568,56 @@ size_t SlCalcObjLength(const void *object, const SaveLoad *sld);
byte SlReadByte(); byte SlReadByte();
void SlWriteByte(byte b); void SlWriteByte(byte b);
static inline int SlReadUint16()
{
int x = SlReadByte() << 8;
return x | SlReadByte();
}
static inline uint32 SlReadUint32()
{
uint32 x = SlReadUint16() << 16;
return x | SlReadUint16();
}
static inline uint64 SlReadUint64()
{
uint32 x = SlReadUint32();
uint32 y = SlReadUint32();
return (uint64)x << 32 | y;
}
static inline void SlWriteUint16(uint16 v)
{
SlWriteByte(GB(v, 8, 8));
SlWriteByte(GB(v, 0, 8));
}
static inline void SlWriteUint32(uint32 v)
{
SlWriteUint16(GB(v, 16, 16));
SlWriteUint16(GB(v, 0, 16));
}
static inline void SlWriteUint64(uint64 x)
{
SlWriteUint32((uint32)(x >> 32));
SlWriteUint32((uint32)x);
}
/**
* Read in bytes from the file/data structure but don't do
* anything with them, discarding them in effect
* @param length The amount of bytes that is being treated this way
*/
static inline void SlSkipBytes(size_t length)
{
for (; length != 0; length--) SlReadByte();
}
size_t SlGetBytesRead();
size_t SlGetBytesWritten();
void SlGlobList(const SaveLoadGlobVarList *sldg); void SlGlobList(const SaveLoadGlobVarList *sldg);
void SlArray(void *array, size_t length, VarType conv); void SlArray(void *array, size_t length, VarType conv);
void SlObject(void *object, const SaveLoad *sld); void SlObject(void *object, const SaveLoad *sld);