Move SlRead/SlWrite functions to saveload.h

Add SlGetBytesRead and SlGetBytesWritten functions.
pull/155/head
Jonathan G Rennison 9 years ago
parent 4508cfbf93
commit a3980dc6ba

@ -649,51 +649,24 @@ void SlWriteByte(byte b)
_sl.dumper->WriteByte(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)
/**
* Returns number of bytes read so far
* May only be called during a load/load check action
*/
size_t SlGetBytesRead()
{
SlWriteUint32((uint32)(x >> 32));
SlWriteUint32((uint32)x);
assert(_sl.action == SLA_LOAD || _sl.action == SLA_LOAD_CHECK);
return _sl.reader->GetSize();
}
/**
* 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
* Returns number of bytes written so far
* May only be called during a save action
*/
static inline void SlSkipBytes(size_t length)
size_t SlGetBytesWritten()
{
for (; length != 0; length--) SlReadByte();
assert(_sl.action == SLA_SAVE);
return _sl.dumper->GetSize();
}
/**

@ -568,6 +568,56 @@ size_t SlCalcObjLength(const void *object, const SaveLoad *sld);
byte SlReadByte();
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 SlArray(void *array, size_t length, VarType conv);
void SlObject(void *object, const SaveLoad *sld);

Loading…
Cancel
Save