stream.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 ********************************************************************/
34 
35 #ifndef ROSBAG_STREAM_H
36 #define ROSBAG_STREAM_H
37 
38 #include <ios>
39 #include <stdint.h>
40 #include <string>
41 
42 #include <boost/shared_ptr.hpp>
43 
44 #include <bzlib.h>
45 
46 #include <roslz4/lz4s.h>
47 
48 #include "rosbag/exceptions.h"
49 #include "rosbag/macros.h"
50 
51 namespace rosbag {
52 
53 namespace compression
54 {
56  {
58  BZ2 = 1,
59  LZ4 = 2,
60  };
61 }
63 
64 class ChunkedFile;
65 
66 class FileAccessor;
67 
69 {
70  friend class FileAccessor;
71 public:
72  Stream(ChunkedFile* file);
73  virtual ~Stream();
74 
75  virtual CompressionType getCompressionType() const = 0;
76 
77  virtual void write(void* ptr, size_t size) = 0;
78  virtual void read (void* ptr, size_t size) = 0;
79 
80  virtual void decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len) = 0;
81 
82  virtual void startWrite();
83  virtual void stopWrite();
84 
85  virtual void startRead();
86  virtual void stopRead();
87 
88 protected:
89  FILE* getFilePointer();
90  uint64_t getCompressedIn();
91  void setCompressedIn(uint64_t nbytes);
92  void advanceOffset(uint64_t nbytes);
93  char* getUnused();
94  int getUnusedLength();
95  void setUnused(char* unused);
96  void setUnusedLength(int nUnused);
97  void clearUnused();
98 
99 protected:
101 };
102 
104 {
105 public:
106  StreamFactory(ChunkedFile* file);
107 
108  boost::shared_ptr<Stream> getStream(CompressionType type) const;
109 
110 private:
114 };
115 
117  friend class ChunkedFile;
118  static void setFile(Stream& a, ChunkedFile* file) {
119  a.file_ = file;
120  }
121 };
122 
124 {
125 public:
127 
128  CompressionType getCompressionType() const;
129 
130  void write(void* ptr, size_t size);
131  void read(void* ptr, size_t size);
132 
133  void decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len);
134 };
135 
140 {
141 public:
142  BZ2Stream(ChunkedFile* file);
143 
144  CompressionType getCompressionType() const;
145 
146  void startWrite();
147  void write(void* ptr, size_t size);
148  void stopWrite();
149 
150  void startRead();
151  void read(void* ptr, size_t size);
152  void stopRead();
153 
154  void decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len);
155 
156 private:
160 
161  BZFILE* bzfile_;
162  int bzerror_;
163 };
164 
165 // LZ4Stream reads/writes compressed datat in the LZ4 format
166 // https://code.google.com/p/lz4/
168 {
169 public:
170  LZ4Stream(ChunkedFile* file);
171  ~LZ4Stream();
172 
173  CompressionType getCompressionType() const;
174 
175  void startWrite();
176  void write(void* ptr, size_t size);
177  void stopWrite();
178 
179  void startRead();
180  void read(void* ptr, size_t size);
181  void stopRead();
182 
183  void decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len);
184 
185 private:
186  LZ4Stream(const LZ4Stream&);
187  LZ4Stream operator=(const LZ4Stream&);
188  void writeStream(int action);
189 
190  char *buff_;
194 };
195 
196 
197 
198 } // namespace rosbag
199 
200 #endif
#define ROSBAG_STORAGE_DECL
Definition: macros.h:50
ChunkedFile reads and writes files which contain interleaved chunks of compressed and uncompressed da...
Definition: chunked_file.h:51
int verbosity_
level of debugging output (0-4; 0 default). 0 is silent, 4 is max verbose debugging output ...
Definition: stream.h:157
boost::shared_ptr< Stream > lz4_stream_
Definition: stream.h:113
roslz4_stream lz4s_
Definition: stream.h:193
int block_size_100k_
compression block size (1-9; 9 default). 9 is best compression, most memory
Definition: stream.h:158
def decompress(data)
int work_factor_
compression behavior for worst case, highly repetitive data (0-250; 30 default)
Definition: stream.h:159
static void setFile(Stream &a, ChunkedFile *file)
Definition: stream.h:118
ChunkedFile * file_
Definition: stream.h:100
char * buff_
Definition: stream.h:190
int block_size_id_
Definition: stream.h:192
BZFILE * bzfile_
bzlib compressed file stream
Definition: stream.h:161
boost::shared_ptr< Stream > bz2_stream_
Definition: stream.h:112
boost::shared_ptr< Stream > uncompressed_stream_
Definition: stream.h:111
int bzerror_
last error from bzlib
Definition: stream.h:162


rosbag_storage
Author(s): Dirk Thomas
autogenerated on Mon Feb 28 2022 23:33:55