diff --git a/io/binaryreader.cpp b/io/binaryreader.cpp
index 9ff5d90..66b7993 100644
--- a/io/binaryreader.cpp
+++ b/io/binaryreader.cpp
@@ -269,7 +269,7 @@ string BinaryReader::readMultibyteTerminatedStringLE(size_t maxBytesToRead, uint
*
* \remarks Cyclic redundancy check (CRC) is an error-detecting code commonly used in
* digital networks and storage devices to detect accidental changes to raw data.
- * \remarks NOT TESTED YET
+ * \remarks Ogg compatible version
* \sa Cyclic redundancy check - Wikipedia
*/
uint32 BinaryReader::readCrc32(size_t length)
@@ -286,13 +286,13 @@ uint32 BinaryReader::readCrc32(size_t length)
*
* \remarks Cyclic redundancy check (CRC) is an error-detecting code commonly used in
* digital networks and storage devices to detect accidental changes to raw data.
- * \remarks NOT TESTED YET
+ * \remarks Ogg compatible version
* \sa Cyclic redundancy check - Wikipedia
*/
uint32 BinaryReader::computeCrc32(const char *buffer, size_t length)
{
uint32 crc = 0x00;
- for(const char *i = buffer, *end = buffer + length; i < end; ++i) {
+ for(const char *i = buffer, *end = buffer + length; i != end; ++i) {
crc = (crc << 8) ^ crc32Table[((crc >> 24) & 0xff) ^ static_cast(*i)];
}
return crc;
diff --git a/io/binaryreader.h b/io/binaryreader.h
index 473d64b..9424a1b 100644
--- a/io/binaryreader.h
+++ b/io/binaryreader.h
@@ -39,7 +39,9 @@ public:
uint32 readUInt24BE();
int32 readInt32BE();
uint32 readUInt32BE();
+ int64 readInt40BE();
uint64 readUInt40BE();
+ int64 readInt56BE();
uint64 readUInt56BE();
int64 readInt64BE();
uint64 readUInt64BE();
@@ -51,7 +53,9 @@ public:
uint32 readUInt24LE();
int32 readInt32LE();
uint32 readUInt32LE();
+ int64 readInt40LE();
uint64 readUInt40LE();
+ int64 readInt56LE();
uint64 readUInt56LE();
int64 readInt64LE();
uint64 readUInt64LE();
@@ -217,7 +221,7 @@ inline int32 BinaryReader::readInt24BE()
{
*m_buffer = 0;
m_stream->read(m_buffer + 1, 3);
- int32 val = ConversionUtilities::BE::toInt32(m_buffer);
+ auto val = ConversionUtilities::BE::toInt32(m_buffer);
if(val >= 0x800000) {
val = -(0x1000000 - val);
}
@@ -252,6 +256,20 @@ inline uint32 BinaryReader::readUInt32BE()
return ConversionUtilities::BE::toUInt32(m_buffer);
}
+/*!
+ * \brief Reads a 40-bit big endian signed integer from the current stream and advances the current position of the stream by five bytes.
+ */
+inline int64 BinaryReader::readInt40BE()
+{
+ *m_buffer = *(m_buffer + 1) = *(m_buffer + 2) = 0;
+ m_stream->read(m_buffer + 3, 5);
+ auto val = ConversionUtilities::BE::toInt64(m_buffer);
+ if(val >= 0x8000000000) {
+ val = -(0x10000000000 - val);
+ }
+ return val;
+}
+
/*!
* \brief Reads a 40-bit big endian unsigned integer from the current stream and advances the current position of the stream by five bytes.
*/
@@ -262,13 +280,27 @@ inline uint64 BinaryReader::readUInt40BE()
return ConversionUtilities::BE::toUInt64(m_buffer);
}
+/*!
+ * \brief Reads a 56-bit big endian signed integer from the current stream and advances the current position of the stream by seven bytes.
+ */
+inline int64 BinaryReader::readInt56BE()
+{
+ *m_buffer = 0;
+ m_stream->read(m_buffer + 1, 7);
+ auto val = ConversionUtilities::BE::toInt64(m_buffer);
+ if(val >= 0x80000000000000) {
+ val = -(0x100000000000000 - val);
+ }
+ return val;
+}
+
/*!
* \brief Reads a 56-bit big endian unsigned integer from the current stream and advances the current position of the stream by seven bytes.
*/
inline uint64 BinaryReader::readUInt56BE()
{
*m_buffer = 0;
- m_stream->read(m_buffer + 1, 5);
+ m_stream->read(m_buffer + 1, 7);
return ConversionUtilities::BE::toUInt64(m_buffer);
}
@@ -333,7 +365,7 @@ inline int32 BinaryReader::readInt24LE()
{
*(m_buffer + 3) = 0;
m_stream->read(m_buffer, 3);
- int32 val = ConversionUtilities::LE::toInt32(m_buffer);
+ auto val = ConversionUtilities::LE::toInt32(m_buffer);
if(val >= 0x800000) {
val = -(0x1000000 - val);
}
@@ -368,6 +400,20 @@ inline uint32 BinaryReader::readUInt32LE()
return ConversionUtilities::LE::toUInt32(m_buffer);
}
+/*!
+ * \brief Reads a 40-bit little endian signed integer from the current stream and advances the current position of the stream by five bytes.
+ */
+inline int64 BinaryReader::readInt40LE()
+{
+ *(m_buffer + 5) = *(m_buffer + 6) = *(m_buffer + 7) = 0;
+ m_stream->read(m_buffer, 5);
+ auto val = ConversionUtilities::LE::toInt64(m_buffer);
+ if(val >= 0x8000000000) {
+ val = -(0x10000000000 - val);
+ }
+ return val;
+}
+
/*!
* \brief Reads a 40-bit little endian unsigned integer from the current stream and advances the current position of the stream by five bytes.
*/
@@ -378,6 +424,20 @@ inline uint64 BinaryReader::readUInt40LE()
return ConversionUtilities::LE::toUInt64(m_buffer);
}
+/*!
+ * \brief Reads a 56-bit little endian signed integer from the current stream and advances the current position of the stream by seven bytes.
+ */
+inline int64 BinaryReader::readInt56LE()
+{
+ *(m_buffer + 7) = 0;
+ m_stream->read(m_buffer, 7);
+ auto val = ConversionUtilities::LE::toInt64(m_buffer);
+ if(val >= 0x80000000000000) {
+ val = -(0x100000000000000 - val);
+ }
+ return val;
+}
+
/*!
* \brief Reads a 56-bit little endian unsigned integer from the current stream and advances the current position of the stream by seven bytes.
*/
diff --git a/io/binarywriter.h b/io/binarywriter.h
index 3bcb9dc..a82f8fd 100644
--- a/io/binarywriter.h
+++ b/io/binarywriter.h
@@ -38,6 +38,10 @@ public:
void writeUInt24BE(uint32 value);
void writeInt32BE(int32 value);
void writeUInt32BE(uint32 value);
+ void writeInt40BE(int64 value);
+ void writeUInt40BE(uint64 value);
+ void writeInt56BE(int64 value);
+ void writeUInt56BE(uint64 value);
void writeInt64BE(int64 value);
void writeUInt64BE(uint64 value);
void writeFloat32BE(float32 value);
@@ -48,6 +52,10 @@ public:
void writeUInt24LE(uint32 value);
void writeInt32LE(int32 value);
void writeUInt32LE(uint32 value);
+ void writeInt40LE(int64 value);
+ void writeUInt40LE(uint64 value);
+ void writeInt56LE(int64 value);
+ void writeUInt56LE(uint64 value);
void writeInt64LE(int64 value);
void writeUInt64LE(uint64 value);
void writeFloat32LE(float32 value);
@@ -243,6 +251,46 @@ inline void BinaryWriter::writeUInt32BE(uint32 value)
m_stream->write(m_buffer, sizeof(uint32));
}
+/*!
+ * \brief Writes a 40-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
+ * \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
+ */
+inline void BinaryWriter::writeInt40BE(int64 value)
+{
+ ConversionUtilities::BE::getBytes(value, m_buffer);
+ m_stream->write(m_buffer + 3, 5);
+}
+
+/*!
+ * \brief Writes a 40-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
+ * \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
+ */
+inline void BinaryWriter::writeUInt40BE(uint64 value)
+{
+ ConversionUtilities::BE::getBytes(value, m_buffer);
+ m_stream->write(m_buffer + 3, 5);
+}
+
+/*!
+ * \brief Writes a 56-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
+ * \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
+ */
+inline void BinaryWriter::writeInt56BE(int64 value)
+{
+ ConversionUtilities::BE::getBytes(value, m_buffer);
+ m_stream->write(m_buffer + 1, 7);
+}
+
+/*!
+ * \brief Writes a 56-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
+ * \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
+ */
+inline void BinaryWriter::writeUInt56BE(uint64 value)
+{
+ ConversionUtilities::BE::getBytes(value, m_buffer);
+ m_stream->write(m_buffer + 1, 7);
+}
+
/*!
* \brief Writes a 64-bit big endian signed integer to the current stream and advances the current position of the stream by eight bytes.
*/
@@ -337,6 +385,46 @@ inline void BinaryWriter::writeUInt32LE(uint32 value)
m_stream->write(m_buffer, sizeof(uint32));
}
+/*!
+ * \brief Writes a 40-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
+ * \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
+ */
+inline void BinaryWriter::writeInt40LE(int64 value)
+{
+ ConversionUtilities::LE::getBytes(value, m_buffer);
+ m_stream->write(m_buffer, 5);
+}
+
+/*!
+ * \brief Writes a 40-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
+ * \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
+ */
+inline void BinaryWriter::writeUInt40LE(uint64 value)
+{
+ ConversionUtilities::LE::getBytes(value, m_buffer);
+ m_stream->write(m_buffer, 5);
+}
+
+/*!
+ * \brief Writes a 56-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
+ * \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
+ */
+inline void BinaryWriter::writeInt56LE(int64 value)
+{
+ ConversionUtilities::LE::getBytes(value, m_buffer);
+ m_stream->write(m_buffer, 7);
+}
+
+/*!
+ * \brief Writes a 56-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
+ * \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
+ */
+inline void BinaryWriter::writeUInt56LE(uint64 value)
+{
+ ConversionUtilities::LE::getBytes(value, m_buffer);
+ m_stream->write(m_buffer, 7);
+}
+
/*!
* \brief Writes a 64-bit little endian signed integer to the current stream and advances the current position of the stream by eight bytes.
*/