Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -526,83 +526,10 @@ * * @return A double from the stream in the native endianess */ - (double)readBigEndianDouble; -/** - * @brief Reads the specified number of uint16_ts from the stream which are - * encoded in big endian. - * - * @warning Only call this when you know that enough data is available! - * Otherwise you will get an exception! - * - * @param buffer A buffer of sufficient size to store the specified number of - * uint16_ts - * @param count The number of uint16_ts to read - * @return The number of bytes read - */ -- (size_t)readBigEndianInt16sIntoBuffer: (uint16_t *)buffer - count: (size_t)count; - -/** - * @brief Reads the specified number of uint32_ts from the stream which are - * encoded in big endian. - * - * @warning Only call this when you know that enough data is available! - * Otherwise you will get an exception! - * - * @param buffer A buffer of sufficient size to store the specified number of - * uint32_ts - * @param count The number of uint32_ts to read - * @return The number of bytes read - */ -- (size_t)readBigEndianInt32sIntoBuffer: (uint32_t *)buffer - count: (size_t)count; - -/** - * @brief Reads the specified number of uint64_ts from the stream which are - * encoded in big endian. - * - * @warning Only call this when you know that enough data is available! - * Otherwise you will get an exception! - * - * @param buffer A buffer of sufficient size to store the specified number of - * uint64_ts - * @param count The number of uint64_ts to read - * @return The number of bytes read - */ -- (size_t)readBigEndianInt64sIntoBuffer: (uint64_t *)buffer - count: (size_t)count; - -/** - * @brief Reads the specified number of floats from the stream which are encoded - * in big endian. - * - * @warning Only call this when you know that enough data is available! - * Otherwise you will get an exception! - * - * @param buffer A buffer of sufficient size to store the specified number of - * floats - * @param count The number of floats to read - * @return The number of bytes read - */ -- (size_t)readBigEndianFloatsIntoBuffer: (float *)buffer count: (size_t)count; - -/** - * @brief Reads the specified number of doubles from the stream which are - * encoded in big endian. - * - * @warning Only call this when you know that enough data is available! - * Otherwise you will get an exception! - * - * @param buffer A buffer of sufficient size to store the specified number of - * doubles - * @param count The number of doubles to read - * @return The number of bytes read - */ -- (size_t)readBigEndianDoublesIntoBuffer: (double *)buffer count: (size_t)count; - /** * @brief Reads a uint16_t from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! @@ -649,85 +576,10 @@ * * @return A double from the stream in the native endianess */ - (double)readLittleEndianDouble; -/** - * @brief Reads the specified number of uint16_ts from the stream which are - * encoded in little endian. - * - * @warning Only call this when you know that enough data is available! - * Otherwise you will get an exception! - * - * @param buffer A buffer of sufficient size to store the specified number of - * uint16_ts - * @param count The number of uint16_ts to read - * @return The number of bytes read - */ -- (size_t)readLittleEndianInt16sIntoBuffer: (uint16_t *)buffer - count: (size_t)count; - -/** - * @brief Reads the specified number of uint32_ts from the stream which are - * encoded in little endian. - * - * @warning Only call this when you know that enough data is available! - * Otherwise you will get an exception! - * - * @param buffer A buffer of sufficient size to store the specified number of - * uint32_ts - * @param count The number of uint32_ts to read - * @return The number of bytes read - */ -- (size_t)readLittleEndianInt32sIntoBuffer: (uint32_t *)buffer - count: (size_t)count; - -/** - * @brief Reads the specified number of uint64_ts from the stream which are - * encoded in little endian. - * - * @warning Only call this when you know that enough data is available! - * Otherwise you will get an exception! - * - * @param buffer A buffer of sufficient size to store the specified number of - * uint64_ts - * @param count The number of uint64_ts to read - * @return The number of bytes read - */ -- (size_t)readLittleEndianInt64sIntoBuffer: (uint64_t *)buffer - count: (size_t)count; - -/** - * @brief Reads the specified number of floats from the stream which are - * encoded in little endian. - * - * @warning Only call this when you know that enough data is available! - * Otherwise you will get an exception! - * - * @param buffer A buffer of sufficient size to store the specified number of - * floats - * @param count The number of floats to read - * @return The number of bytes read - */ -- (size_t)readLittleEndianFloatsIntoBuffer: (float *)buffer - count: (size_t)count; - -/** - * @brief Reads the specified number of doubles from the stream which are - * encoded in little endian. - * - * @warning Only call this when you know that enough data is available! - * Otherwise you will get an exception! - * - * @param buffer A buffer of sufficient size to store the specified number of - * doubles - * @param count The number of doubles to read - * @return The number of bytes read - */ -- (size_t)readLittleEndianDoublesIntoBuffer: (double *)buffer - count: (size_t)count; - /** * @brief Reads the specified number of items with an item size of 1 from the * stream and returns them as OFData. * * @warning Only call this when you know that enough data is available! @@ -1187,70 +1039,10 @@ * * @param double_ A double */ - (void)writeBigEndianDouble: (double)double_; -/** - * @brief Writes the specified number of uint16_ts into the stream, encoded in - * big endian. - * - * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. - * - * @param buffer The buffer from which the data is written to the stream after - * it has been byte swapped if necessary - * @param count The number of uint16_ts to write - */ -- (void)writeBigEndianInt16s: (const uint16_t *)buffer count: (size_t)count; - -/** - * @brief Writes the specified number of uint32_ts into the stream, encoded in - * big endian. - * - * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. - * - * @param buffer The buffer from which the data is written to the stream after - * it has been byte swapped if necessary - * @param count The number of uint32_ts to write - */ -- (void)writeBigEndianInt32s: (const uint32_t *)buffer count: (size_t)count; - -/** - * @brief Writes the specified number of uint64_ts into the stream, encoded in - * big endian. - * - * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. - * - * @param buffer The buffer from which the data is written to the stream after - * it has been byte swapped if necessary - * @param count The number of uint64_ts to write - */ -- (void)writeBigEndianInt64s: (const uint64_t *)buffer count: (size_t)count; - -/** - * @brief Writes the specified number of floats into the stream, encoded in big - * endian. - * - * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. - * - * @param buffer The buffer from which the data is written to the stream after - * it has been byte swapped if necessary - * @param count The number of floats to write - */ -- (void)writeBigEndianFloats: (const float *)buffer count: (size_t)count; - -/** - * @brief Writes the specified number of doubles into the stream, encoded in - * big endian. - * - * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. - * - * @param buffer The buffer from which the data is written to the stream after - * it has been byte swapped if necessary - * @param count The number of doubles to write - */ -- (void)writeBigEndianDoubles: (const double *)buffer count: (size_t)count; - /** * @brief Writes a uint16_t into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * @@ -1292,70 +1084,10 @@ * * @param double_ A double */ - (void)writeLittleEndianDouble: (double)double_; -/** - * @brief Writes the specified number of uint16_ts into the stream, encoded in - * little endian. - * - * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. - * - * @param buffer The buffer from which the data is written to the stream after - * it has been byte swapped if necessary - * @param count The number of uint16_ts to write - */ -- (void)writeLittleEndianInt16s: (const uint16_t *)buffer count: (size_t)count; - -/** - * @brief Writes the specified number of uint32_ts into the stream, encoded in - * little endian. - * - * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. - * - * @param count The number of uint32_ts to write - * @param buffer The buffer from which the data is written to the stream after - * it has been byte swapped if necessary - */ -- (void)writeLittleEndianInt32s: (const uint32_t *)buffer count: (size_t)count; - -/** - * @brief Writes the specified number of uint64_ts into the stream, encoded in - * little endian. - * - * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. - * - * @param buffer The buffer from which the data is written to the stream after - * it has been byte swapped if necessary - * @param count The number of uint64_ts to write - */ -- (void)writeLittleEndianInt64s: (const uint64_t *)buffer count: (size_t)count; - -/** - * @brief Writes the specified number of floats into the stream, encoded in - * little endian. - * - * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. - * - * @param buffer The buffer from which the data is written to the stream after - * it has been byte swapped if necessary - * @param count The number of floats to write - */ -- (void)writeLittleEndianFloats: (const float *)buffer count: (size_t)count; - -/** - * @brief Writes the specified number of doubles into the stream, encoded in - * little endian. - * - * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. - * - * @param buffer The buffer from which the data is written to the stream after - * it has been byte swapped if necessary - * @param count The number of doubles to write - */ -- (void)writeLittleEndianDoubles: (const double *)buffer count: (size_t)count; - /** * @brief Writes OFData into the stream. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -337,105 +337,10 @@ double ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromBigEndianDouble(ret); } -- (size_t)readBigEndianInt16sIntoBuffer: (uint16_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint16_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifndef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap16(buffer[i]); -#endif - - return size; -} - -- (size_t)readBigEndianInt32sIntoBuffer: (uint32_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint32_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifndef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap32(buffer[i]); -#endif - - return size; -} - -- (size_t)readBigEndianInt64sIntoBuffer: (uint64_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint64_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifndef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap64(buffer[i]); -#endif - - return size; -} - -- (size_t)readBigEndianFloatsIntoBuffer: (float *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(float); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifndef OF_FLOAT_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwapFloat(buffer[i]); -#endif - - return size; -} - -- (size_t)readBigEndianDoublesIntoBuffer: (double *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(double); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifndef OF_FLOAT_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwapDouble(buffer[i]); -#endif - - return size; -} - - (uint16_t)readLittleEndianInt16 { uint16_t ret; [self readIntoBuffer: (char *)&ret exactLength: 2]; return OFFromLittleEndian16(ret); @@ -467,110 +372,10 @@ double ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromLittleEndianDouble(ret); } -- (size_t)readLittleEndianInt16sIntoBuffer: (uint16_t *)buffer - count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint16_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifdef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap16(buffer[i]); -#endif - - return size; -} - -- (size_t)readLittleEndianInt32sIntoBuffer: (uint32_t *)buffer - count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint32_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifdef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap32(buffer[i]); -#endif - - return size; -} - -- (size_t)readLittleEndianInt64sIntoBuffer: (uint64_t *)buffer - count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint64_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifdef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap64(buffer[i]); -#endif - - return size; -} - -- (size_t)readLittleEndianFloatsIntoBuffer: (float *)buffer - count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(float); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifdef OF_FLOAT_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwapFloat(buffer[i]); -#endif - - return size; -} - -- (size_t)readLittleEndianDoublesIntoBuffer: (double *)buffer - count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(double); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifdef OF_FLOAT_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwapDouble(buffer[i]); -#endif - - return size; -} - - (OFData *)readDataWithCount: (size_t)count { return [self readDataWithItemSize: 1 count: count]; } @@ -1259,135 +1064,10 @@ { double_ = OFToBigEndianDouble(double_); [self writeBuffer: (char *)&double_ length: 8]; } -- (void)writeBigEndianInt16s: (const uint16_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint16_t); - -#ifdef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap16(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeBigEndianInt32s: (const uint32_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint32_t); - -#ifdef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap32(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeBigEndianInt64s: (const uint64_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint64_t); - -#ifdef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap64(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeBigEndianFloats: (const float *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(float); - -#ifdef OF_FLOAT_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - float *tmp = OFAllocMemory(count, sizeof(float)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwapFloat(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeBigEndianDoubles: (const double *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(double); - -#ifdef OF_FLOAT_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - double *tmp = OFAllocMemory(count, sizeof(double)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwapDouble(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - - (void)writeLittleEndianInt16: (uint16_t)int16 { int16 = OFToLittleEndian16(int16); [self writeBuffer: (char *)&int16 length: 2]; } @@ -1414,135 +1094,10 @@ { double_ = OFToLittleEndianDouble(double_); [self writeBuffer: (char *)&double_ length: 8]; } -- (void)writeLittleEndianInt16s: (const uint16_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint16_t); - -#ifndef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap16(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeLittleEndianInt32s: (const uint32_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint32_t); - -#ifndef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap32(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeLittleEndianInt64s: (const uint64_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint64_t); - -#ifndef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap64(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeLittleEndianFloats: (const float *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(float); - -#ifndef OF_FLOAT_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - float *tmp = OFAllocMemory(count, sizeof(float)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwapFloat(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeLittleEndianDoubles: (const double *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(double); - -#ifndef OF_FLOAT_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - double *tmp = OFAllocMemory(count, sizeof(double)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwapDouble(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - - (void)writeData: (OFData *)data { void *pool; size_t length;