OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef BIN_FILTER_H_ | 5 #ifndef BIN_FILTER_H_ |
6 #define BIN_FILTER_H_ | 6 #define BIN_FILTER_H_ |
7 | 7 |
8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
9 #include "bin/utils.h" | 9 #include "bin/utils.h" |
10 | 10 |
11 #include "../third_party/zlib/zlib.h" | 11 #include "../third_party/zlib/zlib.h" |
12 | 12 |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 namespace bin { | 15 namespace bin { |
16 | 16 |
17 class Filter { | 17 class Filter { |
18 public: | 18 public: |
19 virtual ~Filter() {} | 19 virtual ~Filter() {} |
20 | 20 |
21 virtual bool Init() = 0; | 21 virtual bool Init() = 0; |
22 | 22 |
23 /** | 23 /** |
24 * On a succesfull call to Process, Process will take ownership of data. On | 24 * On a successful call to Process, Process will take ownership of data. On |
25 * successive calls to either Processed or ~Filter, data will be freed with | 25 * successive calls to either Processed or ~Filter, data will be freed with |
26 * a delete[] call. | 26 * a delete[] call. |
27 */ | 27 */ |
28 virtual bool Process(uint8_t* data, intptr_t length) = 0; | 28 virtual bool Process(uint8_t* data, intptr_t length) = 0; |
29 virtual intptr_t Processed(uint8_t* buffer, | 29 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish, |
30 intptr_t length, | |
31 bool finish, | |
32 bool end) = 0; | 30 bool end) = 0; |
33 | 31 |
34 static Dart_Handle SetFilterPointerNativeField(Dart_Handle filter, | 32 static Dart_Handle SetFilterPointerNativeField(Dart_Handle filter, |
35 Filter* filter_pointer); | 33 Filter* filter_pointer); |
36 static Dart_Handle GetFilterPointerNativeField(Dart_Handle filter, | 34 static Dart_Handle GetFilterPointerNativeField(Dart_Handle filter, |
37 Filter** filter_pointer); | 35 Filter** filter_pointer); |
38 | 36 |
39 bool initialized() const { return initialized_; } | 37 bool initialized() const { return initialized_; } |
40 void set_initialized(bool value) { initialized_ = value; } | 38 void set_initialized(bool value) { initialized_ = value; } |
41 uint8_t* processed_buffer() { return processed_buffer_; } | 39 uint8_t* processed_buffer() { return processed_buffer_; } |
42 intptr_t processed_buffer_size() const { return kFilterBufferSize; } | 40 intptr_t processed_buffer_size() const { return kFilterBufferSize; } |
43 | 41 |
44 protected: | 42 protected: |
45 Filter() : initialized_(false) {} | 43 Filter() : initialized_(false) {} |
46 | 44 |
47 private: | 45 private: |
48 static const intptr_t kFilterBufferSize = 64 * KB; | 46 static const intptr_t kFilterBufferSize = 64 * KB; |
49 uint8_t processed_buffer_[kFilterBufferSize]; | 47 uint8_t processed_buffer_[kFilterBufferSize]; |
50 bool initialized_; | 48 bool initialized_; |
51 | 49 |
52 DISALLOW_COPY_AND_ASSIGN(Filter); | 50 DISALLOW_COPY_AND_ASSIGN(Filter); |
53 }; | 51 }; |
54 | 52 |
55 class ZLibDeflateFilter : public Filter { | 53 class ZLibDeflateFilter : public Filter { |
56 public: | 54 public: |
57 ZLibDeflateFilter(bool gzip = false, int32_t level = 6) | 55 ZLibDeflateFilter(bool gzip, int32_t level, int32_t window_bits, |
58 : gzip_(gzip), level_(level), current_buffer_(NULL) {} | 56 int32_t mem_level, int32_t strategy, |
| 57 uint8_t* dictionary, bool raw) |
| 58 : gzip_(gzip), level_(level), window_bits_(window_bits), |
| 59 mem_level_(mem_level), strategy_(strategy), dictionary_(dictionary), |
| 60 raw_(raw), current_buffer_(NULL) |
| 61 {} |
59 virtual ~ZLibDeflateFilter(); | 62 virtual ~ZLibDeflateFilter(); |
60 | 63 |
61 virtual bool Init(); | 64 virtual bool Init(); |
62 virtual bool Process(uint8_t* data, intptr_t length); | 65 virtual bool Process(uint8_t* data, intptr_t length); |
63 virtual intptr_t Processed(uint8_t* buffer, | 66 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish, |
64 intptr_t length, | |
65 bool finish, | |
66 bool end); | 67 bool end); |
67 | 68 |
68 private: | 69 private: |
69 const bool gzip_; | 70 const bool gzip_; |
70 const int32_t level_; | 71 const int32_t level_; |
| 72 const int32_t window_bits_; |
| 73 const int32_t mem_level_; |
| 74 const int32_t strategy_; |
| 75 uint8_t* dictionary_; |
| 76 const bool raw_; |
71 uint8_t* current_buffer_; | 77 uint8_t* current_buffer_; |
72 z_stream stream_; | 78 z_stream stream_; |
73 | 79 |
74 DISALLOW_COPY_AND_ASSIGN(ZLibDeflateFilter); | 80 DISALLOW_COPY_AND_ASSIGN(ZLibDeflateFilter); |
75 }; | 81 }; |
76 | 82 |
77 class ZLibInflateFilter : public Filter { | 83 class ZLibInflateFilter : public Filter { |
78 public: | 84 public: |
79 ZLibInflateFilter() : current_buffer_(NULL) {} | 85 ZLibInflateFilter(int32_t window_bits, uint8_t* dictionary, bool raw) |
| 86 : window_bits_(window_bits), dictionary_(dictionary), raw_(raw), |
| 87 current_buffer_(NULL) |
| 88 {} |
80 virtual ~ZLibInflateFilter(); | 89 virtual ~ZLibInflateFilter(); |
81 | 90 |
82 virtual bool Init(); | 91 virtual bool Init(); |
83 virtual bool Process(uint8_t* data, intptr_t length); | 92 virtual bool Process(uint8_t* data, intptr_t length); |
84 virtual intptr_t Processed(uint8_t* buffer, | 93 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish, |
85 intptr_t length, | |
86 bool finish, | |
87 bool end); | 94 bool end); |
88 | 95 |
89 private: | 96 private: |
| 97 const int32_t window_bits_; |
| 98 uint8_t* dictionary_; |
| 99 const bool raw_; |
90 uint8_t* current_buffer_; | 100 uint8_t* current_buffer_; |
91 z_stream stream_; | 101 z_stream stream_; |
92 | 102 |
93 DISALLOW_COPY_AND_ASSIGN(ZLibInflateFilter); | 103 DISALLOW_COPY_AND_ASSIGN(ZLibInflateFilter); |
94 }; | 104 }; |
95 | 105 |
96 } // namespace bin | 106 } // namespace bin |
97 } // namespace dart | 107 } // namespace dart |
98 | 108 |
99 #endif // BIN_FILTER_H_ | 109 #endif // BIN_FILTER_H_ |
OLD | NEW |