diff options
Diffstat (limited to 'common/stream.h')
-rw-r--r-- | common/stream.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/common/stream.h b/common/stream.h index 1dceb31f16..141e37529c 100644 --- a/common/stream.h +++ b/common/stream.h @@ -389,6 +389,39 @@ public: virtual String readLine(); }; +/** + * This is a ReadStream mixin subclass which adds non-endian read + * methods whose endianness is set du the stream creation. + */ +class ReadStreamEndian : virtual public ReadStream { +private: + const bool _bigEndian; + +public: + ReadStreamEndian(bool bigEndian = false) : _bigEndian(bigEndian) {} + + uint16 readUint16() { + uint16 val; + read(&val, 2); + return (_bigEndian) ? TO_BE_16(val) : TO_LE_16(val); + } + + uint32 readUint32() { + uint32 val; + read(&val, 4); + return (_bigEndian) ? TO_BE_32(val) : TO_LE_32(val); + } + + FORCEINLINE int16 readSint16() { + return (int16)readUint16(); + } + + FORCEINLINE int32 readSint32() { + return (int32)readUint32(); + } +}; + + } // End of namespace Common #endif |