]> git.cworth.org Git - apitrace/blobdiff - trace_snappyfile.cpp
Implement scanning/skipping of fragments of the trace
[apitrace] / trace_snappyfile.cpp
index c13a97940d04c0e0372d42124f8ba2fddafc0723..443ebe7c5040c131bf7eef72daeb84ace273b98b 100644 (file)
@@ -68,7 +68,9 @@ SnappyFile::SnappyFile(const std::string &filename,
       m_cachePtr(0),
       m_cacheSize(0)
 {
-    m_compressedCache = new char[SNAPPY_CHUNK_SIZE];
+    size_t maxCompressedLength =
+        snappy::MaxCompressedLength(SNAPPY_CHUNK_SIZE);
+    m_compressedCache = new char[maxCompressedLength];
 }
 
 SnappyFile::~SnappyFile()
@@ -266,3 +268,27 @@ void SnappyFile::setCurrentOffset(const File::Offset &offset)
     m_cachePtr = m_cache + offset.offsetInChunk;
 
 }
+
+bool SnappyFile::rawSkip(unsigned length)
+{
+    if (endOfData()) {
+        return false;
+    }
+
+    if (freeCacheSize() >= length) {
+        m_cachePtr += length;
+    } else {
+        int sizeToRead = length;
+        while (sizeToRead) {
+            int chunkSize = std::min(freeCacheSize(), sizeToRead);
+            m_cachePtr += chunkSize;
+            sizeToRead -= chunkSize;
+            if (sizeToRead > 0)
+                flushCache();
+            if (!m_cacheSize)
+                break;
+        }
+    }
+
+    return true;
+}