Chromium Code Reviews| Index: runtime/bin/filter.h |
| diff --git a/runtime/bin/filter.h b/runtime/bin/filter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..810b79b7131e2dfc6bf5a6f976a2f3cf94f43226 |
| --- /dev/null |
| +++ b/runtime/bin/filter.h |
| @@ -0,0 +1,70 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +#ifndef BIN_FILTER_H_ |
| +#define BIN_FILTER_H_ |
| + |
| +#include "bin/builtin.h" |
| +#include "bin/utils.h" |
| + |
| +#include "../third_party/zlib/zlib.h" |
| + |
| +class Filter { |
| + protected: |
| + Filter() {} |
| + |
| + public: |
| + virtual ~Filter() {} |
| + |
| + public: |
| + virtual bool Init() = 0; |
| + /** |
| + * On a succesfull call to Process, Process will take ownership of data. |
|
Søren Gjesse
2013/03/05 15:59:05
Please expand comment on how the data will be free
Anders Johnsen
2013/03/06 10:32:46
Done.
|
| + */ |
| + virtual bool Process(uint8_t* data, intptr_t length) = 0; |
| + virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish) = 0; |
| + |
| + |
| + public: |
| + static Dart_Handle SetFilterPointerNativeField(Dart_Handle filter, |
| + Filter* filter_pointer); |
| + static Dart_Handle GetFilterPointerNativeField(Dart_Handle filter, |
| + Filter** filter_pointer); |
| +}; |
| + |
| +class ZLibDeflateFilter : public Filter { |
| + public: |
| + ZLibDeflateFilter(bool gZip = false, int level = 6) |
| + : gZip(gZip), level(level), current_buffer(NULL) {} |
| + virtual ~ZLibDeflateFilter(); |
| + |
| + public: |
| + virtual bool Init(); |
| + virtual bool Process(uint8_t* data, intptr_t length); |
|
Søren Gjesse
2013/03/05 15:59:05
Does the same ownership handover happen here?
Anders Johnsen
2013/03/06 10:32:46
It does, but since it overrides the method, I thin
|
| + virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish); |
| + |
| + private: |
| + const bool gZip; |
| + const int level; |
| + uint8_t* current_buffer; |
| + z_stream stream; |
| +}; |
| + |
| +class ZLibInflateFilter : public Filter { |
| + public: |
| + ZLibInflateFilter() : current_buffer(NULL) {} |
| + virtual ~ZLibInflateFilter(); |
| + |
| + public: |
| + virtual bool Init(); |
| + virtual bool Process(uint8_t* data, intptr_t length); |
| + virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish); |
| + |
| + private: |
| + uint8_t* current_buffer; |
| + z_stream stream; |
| +}; |
| + |
| +#endif // BIN_FILTER_H_ |
| + |