diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/stream.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/common/stream.h b/common/stream.h index d7d96f3605..deb018aad5 100644 --- a/common/stream.h +++ b/common/stream.h @@ -402,6 +402,35 @@ public: void seek(int32 offs, int whence = SEEK_SET); }; + +/** + * This is a wrapper around MemoryReadStream, but it adds non-endian + * read methods whose endianness is set on the stream creation. + */ +class MemoryReadStreamEndian : public Common::MemoryReadStream { +private: +public: + bool _bigEndian; + MemoryReadStreamEndian(const byte *buf, uint32 len, bool bigEndian = false) : MemoryReadStream(buf, len), _bigEndian(bigEndian) {} + + uint16 readUint16() { + return (_bigEndian) ? readUint16BE(): readUint16LE(); + } + + uint32 readUint32() { + return (_bigEndian) ? readUint32BE(): readUint32LE(); + } + + inline int16 readSint16() { + return (int16)readUint16(); + } + + + inline int32 readSint32() { + return (int32)readUint32(); + } +}; + /** * Simple memory based 'stream', which implements the WriteStream interface for * a plain memory block. |