Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -87,10 +87,31 @@ * * \return An uint64_t from the stream in the native endianess */ - (uint64_t)readBigEndianInt64; +/** + * Reads an uint16_t from the stream which is encoded in little endian. + * + * \return An uint16_t from the stream in native endianess + */ +- (uint16_t)readLittleEndianInt16; + +/** + * Reads an uint32_t from the stream which is encoded in little endian. + * + * \return An uint32_t from the stream in the native endianess + */ +- (uint32_t)readLittleEndianInt32; + +/** + * Reads an uint64_t from the stream which is encoded in little endian. + * + * \return An uint64_t from the stream in the native endianess + */ +- (uint64_t)readLittleEndianInt64; + /** * Reads nitems items with the specified item size from the stream and returns * them in an OFDataArray. * * \param itemsize The size of each item @@ -190,10 +211,31 @@ * * \param int64 An uint64_t */ - (void)writeBigEndianInt64: (uint64_t)int64; +/** + * Writes an uint16_t into the stream, encoded in little endian. + * + * \param int16 An uint16_t + */ +- (void)writeLittleEndianInt16: (uint16_t)int16; + +/** + * Writes an uint32_t into the stream, encoded in little endian. + * + * \param int32 An uint32_t + */ +- (void)writeLittleEndianInt32: (uint32_t)int32; + +/** + * Writes an uint64_t into the stream, encoded in little endian. + * + * \param int64 An uint64_t + */ +- (void)writeLittleEndianInt64: (uint64_t)int64; + /** * Writes from an OFDataArray into the stream. * * \param dataarray The OFDataArray to write into the stream * \return The number of bytes written Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -147,10 +147,40 @@ [self readExactlyNBytes: 8 intoBuffer: (char*)&ret]; return OF_BSWAP64_IF_LE(ret); } + +- (uint16_t)readLittleEndianInt16 +{ + uint16_t ret; + + [self readExactlyNBytes: 2 + intoBuffer: (char*)&ret]; + + return OF_BSWAP16_IF_BE(ret); +} + +- (uint32_t)readLittleEndianInt32 +{ + uint32_t ret; + + [self readExactlyNBytes: 4 + intoBuffer: (char*)&ret]; + + return OF_BSWAP32_IF_BE(ret); +} + +- (uint64_t)readLittleEndianInt64 +{ + uint64_t ret; + + [self readExactlyNBytes: 8 + intoBuffer: (char*)&ret]; + + return OF_BSWAP64_IF_BE(ret); +} - (OFDataArray*)readDataArrayWithItemSize: (size_t)itemsize andNItems: (size_t)nitems { OFDataArray *da; @@ -527,10 +557,34 @@ - (void)writeBigEndianInt64: (uint64_t)int64 { int64 = OF_BSWAP64_IF_LE(int64); + [self writeNBytes: 8 + fromBuffer: (char*)&int64]; +} + +- (void)writeLittleEndianInt16: (uint16_t)int16 +{ + int16 = OF_BSWAP16_IF_BE(int16); + + [self writeNBytes: 2 + fromBuffer: (char*)&int16]; +} + +- (void)writeLittleEndianInt32: (uint32_t)int32 +{ + int32 = OF_BSWAP32_IF_BE(int32); + + [self writeNBytes: 4 + fromBuffer: (char*)&int32]; +} + +- (void)writeLittleEndianInt64: (uint64_t)int64 +{ + int64 = OF_BSWAP64_IF_BE(int64); + [self writeNBytes: 8 fromBuffer: (char*)&int64]; } - (size_t)writeDataArray: (OFDataArray*)dataarray