Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -84,10 +84,39 @@ * \param size The size of the data that should be read. * The buffer MUST be EXACTLY this big! */ - (void)readExactlyNBytes: (size_t)size intoBuffer: (char*)buf; + +/** + * Reads an uint8_t from the stream. + * + * \return An uint8_t from the stream + */ +- (uint8_t)readInt8; + +/** + * Reads an uint16_t from the stream which is encoded in big endian. + * + * \return An uint16_t from the stream in native endianess + */ +- (uint16_t)readBigEndianInt16; + +/** + * Reads an uint32_t from the stream which is encoded in big endian. + * + * \return An uint32_t from the stream in the native endianess + */ +- (uint32_t)readBigEndianInt32; + +/** + * Reads an uint64_t from the stream which is encoded in big endian. + * + * \return An uint64_t from the stream in the native endianess + */ +- (uint64_t)readBigEndianInt64; + /** * Reads nitems items with the specified item size from the stream and returns * them in an OFDataArray. * * \param itemsize The size of each item Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -99,10 +99,50 @@ while (len < size) len += [self readNBytes: size - len intoBuffer: buf + len]; } + +- (uint8_t)readInt8 +{ + uint8_t ret; + + [self readExactlyNBytes: 1 + intoBuffer: (char*)&ret]; + + return ret; +} + +- (uint16_t)readBigEndianInt16 +{ + uint16_t ret; + + [self readExactlyNBytes: 2 + intoBuffer: (char*)&ret]; + + return OF_BSWAP16_IF_LE(ret); +} + +- (uint32_t)readBigEndianInt32 +{ + uint32_t ret; + + [self readExactlyNBytes: 4 + intoBuffer: (char*)&ret]; + + return OF_BSWAP32_IF_LE(ret); +} + +- (uint64_t)readBigEndianInt64 +{ + uint64_t ret; + + [self readExactlyNBytes: 8 + intoBuffer: (char*)&ret]; + + return OF_BSWAP64_IF_LE(ret); +} - (OFDataArray*)readDataArrayWithItemSize: (size_t)itemsize andNItems: (size_t)nitems { OFDataArray *da;