From 75e8c9b7c7f2f10d9b7f479d45f58d81ea729d30 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Thu, 25 Aug 2011 00:02:20 -0400 Subject: [PATCH] Make sure that the size of the compressed length is constant. size_t can differ between 32 and 64 bit systems. Plus add some documentation about the file format. --- trace_snappyfile.cpp | 32 +++++++++++++++++++++++++++++--- trace_snappyfile.hpp | 6 ++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/trace_snappyfile.cpp b/trace_snappyfile.cpp index 45cd95a..2dc5cb3 100644 --- a/trace_snappyfile.cpp +++ b/trace_snappyfile.cpp @@ -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; } diff --git a/trace_snappyfile.hpp b/trace_snappyfile.hpp index 0cafa98..601bc12 100644 --- a/trace_snappyfile.hpp +++ b/trace_snappyfile.hpp @@ -6,6 +6,8 @@ #include #include +#include + 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; -- 2.43.0