]> git.cworth.org Git - apitrace/blobdiff - trace_snappyfile.cpp
Merge branch 'master' into on-demand-loading
[apitrace] / trace_snappyfile.cpp
index ad0a57749a784ae7148ee056e4115c6f360980b2..c13a97940d04c0e0372d42124f8ba2fddafc0723 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <snappy.h>
 
+#include <iostream>
+
 #include <assert.h>
 #include <string.h>
 
@@ -199,6 +201,7 @@ void SnappyFile::flushCache()
         if (m_stream.eof())
             return;
         //assert(m_cachePtr == m_cache + m_cacheSize);
+        m_currentOffset.chunk = m_stream.tellg();
         size_t compressedLength;
         compressedLength = readCompressedLength();
         m_stream.read((char*)m_compressedCache, compressedLength);
@@ -238,3 +241,28 @@ uint32_t SnappyFile::readCompressedLength()
     m_stream.read((char*)&len, sizeof len);
     return len;
 }
+
+bool SnappyFile::supportsOffsets() const
+{
+    return true;
+}
+
+File::Offset SnappyFile::currentOffset()
+{
+    m_currentOffset.offsetInChunk = m_cachePtr - m_cache;
+    return m_currentOffset;
+}
+
+void SnappyFile::setCurrentOffset(const File::Offset &offset)
+{
+    // to remove eof bit
+    m_stream.clear();
+    // seek to the start of a chunk
+    m_stream.seekg(offset.chunk, std::ios::beg);
+    // load the chunk
+    flushCache();
+    assert(m_cacheSize >= offset.offsetInChunk);
+    // seek within our cache to the correct location within the chunk
+    m_cachePtr = m_cache + offset.offsetInChunk;
+
+}