1 | /* |
---|
2 | * ====================================================================== |
---|
3 | * Rappture::Buffer |
---|
4 | * |
---|
5 | * AUTHOR: Derrick Kearney, Purdue University |
---|
6 | * |
---|
7 | * Copyright (c) 2004-2008 Purdue Research Foundation |
---|
8 | * ---------------------------------------------------------------------- |
---|
9 | * See the file "license.terms" for information on usage and |
---|
10 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
11 | * ====================================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | #ifndef RAPPTURE_BUFFER_H |
---|
15 | #define RAPPTURE_BUFFER_H |
---|
16 | |
---|
17 | #include <RpOutcome.h> |
---|
18 | #include <RpSimpleBuffer.h> |
---|
19 | |
---|
20 | enum RapptureEncodingFlags { |
---|
21 | RPENC_Z=(1<<0), |
---|
22 | RPENC_B64=(1<<1), |
---|
23 | RPENC_HDR=(1<<2), |
---|
24 | RPENC_RAW=(1<<3) |
---|
25 | }; |
---|
26 | |
---|
27 | |
---|
28 | #ifdef __cplusplus |
---|
29 | extern "C" { |
---|
30 | #endif // ifdef __cplusplus |
---|
31 | |
---|
32 | enum RP_COMPRESS_CONSTS { |
---|
33 | RPCOMPRESS_ZLIB = 0, |
---|
34 | RPCOMPRESS_GZIP = 16 |
---|
35 | }; |
---|
36 | |
---|
37 | namespace Rappture { |
---|
38 | |
---|
39 | /** |
---|
40 | * Block of memory that dynamically resizes itself as needed. |
---|
41 | * The buffer also allows caller to massage the data it holds |
---|
42 | * with functionallity including gzip compression based on zlib |
---|
43 | * and base64 encoding based on libb64. |
---|
44 | */ |
---|
45 | |
---|
46 | class Buffer : public SimpleCharBuffer{ |
---|
47 | public: |
---|
48 | Buffer(); |
---|
49 | Buffer(int nbytes); |
---|
50 | Buffer(const char* bytes, int nbytes=-1); |
---|
51 | Buffer(const Buffer& buffer); |
---|
52 | Buffer& operator=(const Buffer& b); |
---|
53 | Buffer operator+(const Buffer& b) const; |
---|
54 | Buffer& operator+=(const Buffer& b); |
---|
55 | virtual ~Buffer(); |
---|
56 | |
---|
57 | bool load(Outcome &result, const char* filePath); |
---|
58 | bool dump(Outcome &result, const char* filePath); |
---|
59 | bool encode(Outcome &result, unsigned int flags = RPENC_Z | RPENC_B64); |
---|
60 | bool decode(Outcome &result, unsigned int flags = RPENC_Z | RPENC_B64); |
---|
61 | |
---|
62 | protected: |
---|
63 | |
---|
64 | /// Compression level for the zlib functions |
---|
65 | int _level; |
---|
66 | |
---|
67 | /// compression type for the zlib functions. |
---|
68 | int _compressionType; |
---|
69 | |
---|
70 | /// number of window bits, adjusts speed of compression |
---|
71 | int _windowBits; |
---|
72 | |
---|
73 | enum { CHUNK = 4096 }; |
---|
74 | |
---|
75 | bool do_compress(Outcome& status, SimpleCharBuffer& bin, |
---|
76 | SimpleCharBuffer& bout ); |
---|
77 | bool do_decompress( Outcome& status, SimpleCharBuffer& bin, |
---|
78 | SimpleCharBuffer& bout ); |
---|
79 | bool do_base64_enc(Outcome& status, const SimpleCharBuffer& bin, |
---|
80 | SimpleCharBuffer& bout ); |
---|
81 | bool do_base64_dec(Outcome& status, const SimpleCharBuffer& bin, |
---|
82 | SimpleCharBuffer& bout ); |
---|
83 | }; |
---|
84 | |
---|
85 | } // namespace Rappture |
---|
86 | |
---|
87 | #ifdef __cplusplus |
---|
88 | } |
---|
89 | #endif // ifdef __cplusplus |
---|
90 | |
---|
91 | #endif // RAPPTURE_BUFFER_H |
---|