]> git.cworth.org Git - apitrace/blob - trace_snappyfile.hpp
Export SnappyFile class to its own file.
[apitrace] / trace_snappyfile.hpp
1 #ifndef TRACE_SNAPPYFILE_HPP
2 #define TRACE_SNAPPYFILE_HPP
3
4 #include "trace_file.hpp"
5
6 #include <string>
7 #include <fstream>
8
9 namespace snappy {
10     class File;
11 }
12
13 namespace Trace {
14
15 #define SNAPPY_CHUNK_SIZE (1 * 1024 * 1024)
16
17 #define SNAPPY_BYTE1 'a'
18 #define SNAPPY_BYTE2 't'
19
20
21 class SnappyFile : public File {
22 public:
23     SnappyFile(const std::string &filename = std::string(),
24                File::Mode mode = File::Read);
25     virtual ~SnappyFile();
26
27 protected:
28     virtual bool rawOpen(const std::string &filename, File::Mode mode);
29     virtual bool rawWrite(const void *buffer, int length);
30     virtual bool rawRead(void *buffer, int length);
31     virtual int rawGetc();
32     virtual void rawClose();
33     virtual void rawFlush(FlushType type);
34
35 private:
36     inline int freeCacheSize() const
37     {
38         if (m_cacheSize > 0)
39             return m_cacheSize - (m_cachePtr - m_cache);
40         else
41             return 0;
42     }
43     void flushCache();
44     void createCache(size_t size);
45 private:
46     std::fstream m_stream;
47     char *m_cache;
48     char *m_cachePtr;
49     size_t m_cacheSize;
50
51     char *m_compressedCache;
52 };
53
54 }
55
56 #endif // TRACE_SNAPPYFILE_HPP