| 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 succesfull 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, intptr_t length, bool finish) = 0; | 29 virtual intptr_t Processed(uint8_t* buffer, |
| 30 intptr_t length, |
| 31 bool finish, |
| 32 bool end) = 0; |
| 30 | 33 |
| 31 static Dart_Handle SetFilterPointerNativeField(Dart_Handle filter, | 34 static Dart_Handle SetFilterPointerNativeField(Dart_Handle filter, |
| 32 Filter* filter_pointer); | 35 Filter* filter_pointer); |
| 33 static Dart_Handle GetFilterPointerNativeField(Dart_Handle filter, | 36 static Dart_Handle GetFilterPointerNativeField(Dart_Handle filter, |
| 34 Filter** filter_pointer); | 37 Filter** filter_pointer); |
| 35 | 38 |
| 36 bool initialized() const { return initialized_; } | 39 bool initialized() const { return initialized_; } |
| 37 void set_initialized(bool value) { initialized_ = value; } | 40 void set_initialized(bool value) { initialized_ = value; } |
| 38 uint8_t* processed_buffer() { return processed_buffer_; } | 41 uint8_t* processed_buffer() { return processed_buffer_; } |
| 39 intptr_t processed_buffer_size() const { return kFilterBufferSize; } | 42 intptr_t processed_buffer_size() const { return kFilterBufferSize; } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 }; | 53 }; |
| 51 | 54 |
| 52 class ZLibDeflateFilter : public Filter { | 55 class ZLibDeflateFilter : public Filter { |
| 53 public: | 56 public: |
| 54 ZLibDeflateFilter(bool gzip = false, int level = 6) | 57 ZLibDeflateFilter(bool gzip = false, int level = 6) |
| 55 : gzip_(gzip), level_(level), current_buffer_(NULL) {} | 58 : gzip_(gzip), level_(level), current_buffer_(NULL) {} |
| 56 virtual ~ZLibDeflateFilter(); | 59 virtual ~ZLibDeflateFilter(); |
| 57 | 60 |
| 58 virtual bool Init(); | 61 virtual bool Init(); |
| 59 virtual bool Process(uint8_t* data, intptr_t length); | 62 virtual bool Process(uint8_t* data, intptr_t length); |
| 60 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish); | 63 virtual intptr_t Processed(uint8_t* buffer, |
| 64 intptr_t length, |
| 65 bool finish, |
| 66 bool end); |
| 61 | 67 |
| 62 private: | 68 private: |
| 63 const bool gzip_; | 69 const bool gzip_; |
| 64 const int level_; | 70 const int level_; |
| 65 uint8_t* current_buffer_; | 71 uint8_t* current_buffer_; |
| 66 z_stream stream_; | 72 z_stream stream_; |
| 67 | 73 |
| 68 DISALLOW_COPY_AND_ASSIGN(ZLibDeflateFilter); | 74 DISALLOW_COPY_AND_ASSIGN(ZLibDeflateFilter); |
| 69 }; | 75 }; |
| 70 | 76 |
| 71 class ZLibInflateFilter : public Filter { | 77 class ZLibInflateFilter : public Filter { |
| 72 public: | 78 public: |
| 73 ZLibInflateFilter() : current_buffer_(NULL) {} | 79 ZLibInflateFilter() : current_buffer_(NULL) {} |
| 74 virtual ~ZLibInflateFilter(); | 80 virtual ~ZLibInflateFilter(); |
| 75 | 81 |
| 76 virtual bool Init(); | 82 virtual bool Init(); |
| 77 virtual bool Process(uint8_t* data, intptr_t length); | 83 virtual bool Process(uint8_t* data, intptr_t length); |
| 78 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish); | 84 virtual intptr_t Processed(uint8_t* buffer, |
| 85 intptr_t length, |
| 86 bool finish, |
| 87 bool end); |
| 79 | 88 |
| 80 private: | 89 private: |
| 81 uint8_t* current_buffer_; | 90 uint8_t* current_buffer_; |
| 82 z_stream stream_; | 91 z_stream stream_; |
| 83 | 92 |
| 84 DISALLOW_COPY_AND_ASSIGN(ZLibInflateFilter); | 93 DISALLOW_COPY_AND_ASSIGN(ZLibInflateFilter); |
| 85 }; | 94 }; |
| 86 | 95 |
| 87 } // namespace bin | 96 } // namespace bin |
| 88 } // namespace dart | 97 } // namespace dart |
| 89 | 98 |
| 90 #endif // BIN_FILTER_H_ | 99 #endif // BIN_FILTER_H_ |
| OLD | NEW |