X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=trace_snappyfile.cpp;h=c350013d7f1acc7e7ff1546fa860019f94d47762;hb=2257168033b52be3094efdbd7eadff8eb77a4c4e;hp=7e7072543426851c125257d2c9d0b5e0367e3e86;hpb=d4ca4e2090572b9bf8430c9d4ece5cb9c9b6528e;p=apitrace diff --git a/trace_snappyfile.cpp b/trace_snappyfile.cpp index 7e70725..c350013 100644 --- a/trace_snappyfile.cpp +++ b/trace_snappyfile.cpp @@ -28,6 +28,8 @@ #include +#include + #include #include @@ -205,6 +207,7 @@ void SnappyFile::flushCache() assert(m_cachePtr == m_cache); } else if (m_mode == File::Read) { //assert(m_cachePtr == m_cache + m_cacheSize); + m_currentOffset.chunk = m_stream.tellg(); size_t compressedLength; compressedLength = readCompressedLength(); @@ -265,3 +268,52 @@ size_t SnappyFile::readCompressedLength() } return length; } + +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; + +} + +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; +}