Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
filter.h
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_BIN_FILTER_H_
6#define RUNTIME_BIN_FILTER_H_
7
8#include "bin/builtin.h"
9#include "bin/utils.h"
10
11#include "zlib/zlib.h"
12
13namespace dart {
14namespace bin {
15
16class Filter {
17 public:
18 virtual ~Filter() {}
19
20 virtual bool Init() = 0;
21
22 /**
23 * On a successful 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,
29 intptr_t length,
30 bool finish,
31 bool end) = 0;
32
34 Filter* filter_pointer,
35 intptr_t filter_size);
37 Filter** filter_pointer);
38
39 bool initialized() const { return initialized_; }
40 void set_initialized(bool value) { initialized_ = value; }
41 uint8_t* processed_buffer() { return processed_buffer_; }
42 intptr_t processed_buffer_size() const { return kFilterBufferSize; }
43
44 protected:
45 Filter() : initialized_(false) {}
46
47 private:
48 static constexpr intptr_t kFilterBufferSize = 64 * KB;
49 uint8_t processed_buffer_[kFilterBufferSize];
50 bool initialized_;
51
53};
54
55class ZLibDeflateFilter : public Filter {
56 public:
58 int32_t level,
59 int32_t window_bits,
60 int32_t mem_level,
61 int32_t strategy,
62 uint8_t* dictionary,
63 intptr_t dictionary_length,
64 bool raw)
65 : gzip_(gzip),
66 level_(level),
67 window_bits_(window_bits),
68 mem_level_(mem_level),
69 strategy_(strategy),
70 dictionary_(dictionary),
71 dictionary_length_(dictionary_length),
72 raw_(raw),
73 current_buffer_(nullptr) {}
74 virtual ~ZLibDeflateFilter();
75
76 virtual bool Init();
77 virtual bool Process(uint8_t* data, intptr_t length);
78 virtual intptr_t Processed(uint8_t* buffer,
79 intptr_t length,
80 bool finish,
81 bool end);
82
83 private:
84 const bool gzip_;
85 const int32_t level_;
86 const int32_t window_bits_;
87 const int32_t mem_level_;
88 const int32_t strategy_;
89 uint8_t* dictionary_;
90 const intptr_t dictionary_length_;
91 const bool raw_;
92 uint8_t* current_buffer_;
93 z_stream stream_;
94
96};
97
98class ZLibInflateFilter : public Filter {
99 public:
100 ZLibInflateFilter(int32_t window_bits,
101 uint8_t* dictionary,
102 intptr_t dictionary_length,
103 bool raw)
104 : window_bits_(window_bits),
105 dictionary_(dictionary),
106 dictionary_length_(dictionary_length),
107 raw_(raw),
108 current_buffer_(nullptr) {}
109 virtual ~ZLibInflateFilter();
110
111 virtual bool Init();
112 virtual bool Process(uint8_t* data, intptr_t length);
113 virtual intptr_t Processed(uint8_t* buffer,
114 intptr_t length,
115 bool finish,
116 bool end);
117
118 private:
119 const int32_t window_bits_;
120 uint8_t* dictionary_;
121 const intptr_t dictionary_length_;
122 const bool raw_;
123 uint8_t* current_buffer_;
124 z_stream stream_;
125
127};
128
129} // namespace bin
130} // namespace dart
131
132#endif // RUNTIME_BIN_FILTER_H_
static Dart_Handle GetFilterNativeField(Dart_Handle filter, Filter **filter_pointer)
Definition filter.cc:278
static Dart_Handle SetFilterAndCreateFinalizer(Dart_Handle filter, Filter *filter_pointer, intptr_t filter_size)
Definition filter.cc:264
virtual intptr_t Processed(uint8_t *buffer, intptr_t length, bool finish, bool end)=0
virtual bool Process(uint8_t *data, intptr_t length)=0
intptr_t processed_buffer_size() const
Definition filter.h:42
virtual ~Filter()
Definition filter.h:18
bool initialized() const
Definition filter.h:39
uint8_t * processed_buffer()
Definition filter.h:41
virtual bool Init()=0
void set_initialized(bool value)
Definition filter.h:40
virtual intptr_t Processed(uint8_t *buffer, intptr_t length, bool finish, bool end)
Definition filter.cc:340
ZLibDeflateFilter(bool gzip, int32_t level, int32_t window_bits, int32_t mem_level, int32_t strategy, uint8_t *dictionary, intptr_t dictionary_length, bool raw)
Definition filter.h:57
virtual intptr_t Processed(uint8_t *buffer, intptr_t length, bool finish, bool end)
Definition filter.cc:405
ZLibInflateFilter(int32_t window_bits, uint8_t *dictionary, intptr_t dictionary_length, bool raw)
Definition filter.h:100
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
glong glong end
static const uint8_t buffer[]
uint8_t value
size_t length
constexpr intptr_t KB
Definition globals.h:528
static int8_t data[kExtLength]
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581