X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=trace_snappyfile.cpp;h=07a62f6bcc187edb38875a43122abfee2c3ddc7d;hb=f562f318ddee6da2041696887e2195fc3c96d740;hp=5804c3bbb2dc76f9e731554329745ee56b7b53de;hpb=51fade4dcdd16dd03e5fc28e5a63cb5f8a95aa28;p=apitrace diff --git a/trace_snappyfile.cpp b/trace_snappyfile.cpp index 5804c3b..07a62f6 100644 --- a/trace_snappyfile.cpp +++ b/trace_snappyfile.cpp @@ -28,6 +28,8 @@ #include +#include + #include #include @@ -201,6 +203,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); @@ -240,3 +243,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; + +}