]> git.cworth.org Git - apitrace/commitdiff
Make sure that the size of the compressed length is constant.
authorZack Rusin <zack@kde.org>
Thu, 25 Aug 2011 04:02:20 +0000 (00:02 -0400)
committerZack Rusin <zack@kde.org>
Thu, 25 Aug 2011 04:02:20 +0000 (00:02 -0400)
size_t can differ between 32 and 64 bit systems.
Plus add some documentation about the file format.

trace_snappyfile.cpp
trace_snappyfile.hpp

index 45cd95a8acca4942b1bec6c29a916ae8b90742c3..2dc5cb3c1ff30db001dd1d1e7d6d8800b5f83f9c 100644 (file)
@@ -7,6 +7,32 @@
 
 using namespace Trace;
 
+/*
+ * Snappy file format.
+ * -------------------
+ *
+ * Snappy at its core is just a compressoin algorithm so we're
+ * creating a new file format which uses snappy compression
+ * to hold the trace data.
+ *
+ * The file is composed of a number of chunks, they are:
+ * chunk {
+ *     uint32 - specifying the length of the compressed data
+ *     compressed data
+ * }
+ * File can contain any number of such chunks.
+ * The default size of an uncompressed chunk is specified in
+ * SNAPPY_CHUNK_SIZE.
+ *
+ * Note:
+ * Currently the default size for a a to-be-compressed data is
+ * 1mb, meaning that the compressed data will be <= 1mb.
+ * The reason it's 1mb is because it seems
+ * to offer a pretty good compression/disk io speed ratio
+ * but that might change.
+ *
+ */
+
 SnappyFile::SnappyFile(const std::string &filename,
                               File::Mode mode)
     : File(),
@@ -172,14 +198,14 @@ void SnappyFile::createCache(size_t size)
     m_cacheSize = size;
 }
 
-void SnappyFile::writeCompressedLength(size_t value)
+void SnappyFile::writeCompressedLength(uint32_t value)
 {
     m_stream.write((char*)&value, sizeof value);
 }
 
-size_t SnappyFile::readCompressedLength()
+uint32_t SnappyFile::readCompressedLength()
 {
-    size_t len;
+    uint32_t len;
     m_stream.read((char*)&len, sizeof len);
     return len;
 }
index 0cafa98fbd0fabb98da24427b74448b03581c212..601bc12d0154ebab6a8b13b248adc3c8d6b91775 100644 (file)
@@ -6,6 +6,8 @@
 #include <string>
 #include <fstream>
 
+#include <stdint.h>
+
 namespace snappy {
     class File;
 }
@@ -42,8 +44,8 @@ private:
     }
     void flushCache();
     void createCache(size_t size);
-    void writeCompressedLength(size_t num);
-    size_t readCompressedLength();
+    void writeCompressedLength(uint32_t  num);
+    uint32_t readCompressedLength();
 private:
     std::fstream m_stream;
     char *m_cache;