]> git.cworth.org Git - apitrace/blobdiff - trace_snappyfile.cpp
Fix writing/reading compressed length of the chunks.
[apitrace] / trace_snappyfile.cpp
index 457f7e9529604d211ba86ce82e3900a4d80486af..45cd95a8acca4942b1bec6c29a916ae8b90742c3 100644 (file)
@@ -145,7 +145,7 @@ void SnappyFile::flushCache()
         ::snappy::RawCompress(m_cache, SNAPPY_CHUNK_SIZE - freeCacheSize(),
                               m_compressedCache, &compressedLength);
 
-        m_stream << compressedLength;
+        writeCompressedLength(compressedLength);
         m_stream.write(m_compressedCache, compressedLength);
         m_cachePtr = m_cache;
     } else if (m_mode == File::Read) {
@@ -153,7 +153,7 @@ void SnappyFile::flushCache()
             return;
         //assert(m_cachePtr == m_cache + m_cacheSize);
         size_t compressedLength;
-        m_stream >> compressedLength;
+        compressedLength = readCompressedLength();
         m_stream.read((char*)m_compressedCache, compressedLength);
         ::snappy::GetUncompressedLength(m_compressedCache, compressedLength,
                                         &m_cacheSize);
@@ -171,3 +171,15 @@ void SnappyFile::createCache(size_t size)
     m_cachePtr = m_cache;
     m_cacheSize = size;
 }
+
+void SnappyFile::writeCompressedLength(size_t value)
+{
+    m_stream.write((char*)&value, sizeof value);
+}
+
+size_t SnappyFile::readCompressedLength()
+{
+    size_t len;
+    m_stream.read((char*)&len, sizeof len);
+    return len;
+}