| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #ifndef BIN_FILTER_H_ |
| 6 #define BIN_FILTER_H_ |
| 7 |
| 8 #include "bin/builtin.h" |
| 9 #include "bin/utils.h" |
| 10 |
| 11 #include "../third_party/zlib/zlib.h" |
| 12 |
| 13 class Filter { |
| 14 protected: |
| 15 Filter() : initialized(false) {} |
| 16 |
| 17 public: |
| 18 virtual ~Filter() {} |
| 19 |
| 20 public: |
| 21 virtual bool Init() = 0; |
| 22 /** |
| 23 * On a succesfull call to Process, Process will take ownership of data. On |
| 24 * successive calls to either Processed or ~Filter, data will be freed with |
| 25 * a delete[] call. |
| 26 */ |
| 27 virtual bool Process(uint8_t* data, intptr_t length) = 0; |
| 28 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish) = 0; |
| 29 |
| 30 |
| 31 public: |
| 32 static Dart_Handle SetFilterPointerNativeField(Dart_Handle filter, |
| 33 Filter* filter_pointer); |
| 34 static Dart_Handle GetFilterPointerNativeField(Dart_Handle filter, |
| 35 Filter** filter_pointer); |
| 36 |
| 37 protected: |
| 38 bool initialized; |
| 39 }; |
| 40 |
| 41 class ZLibDeflateFilter : public Filter { |
| 42 public: |
| 43 ZLibDeflateFilter(bool gZip = false, int level = 6) |
| 44 : gZip(gZip), level(level), current_buffer(NULL) {} |
| 45 virtual ~ZLibDeflateFilter(); |
| 46 |
| 47 public: |
| 48 virtual bool Init(); |
| 49 virtual bool Process(uint8_t* data, intptr_t length); |
| 50 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish); |
| 51 |
| 52 private: |
| 53 const bool gZip; |
| 54 const int level; |
| 55 uint8_t* current_buffer; |
| 56 z_stream stream; |
| 57 }; |
| 58 |
| 59 class ZLibInflateFilter : public Filter { |
| 60 public: |
| 61 ZLibInflateFilter() : current_buffer(NULL) {} |
| 62 virtual ~ZLibInflateFilter(); |
| 63 |
| 64 public: |
| 65 virtual bool Init(); |
| 66 virtual bool Process(uint8_t* data, intptr_t length); |
| 67 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish); |
| 68 |
| 69 private: |
| 70 uint8_t* current_buffer; |
| 71 z_stream stream; |
| 72 }; |
| 73 |
| 74 #endif // BIN_FILTER_H_ |
| 75 |
| OLD | NEW |