webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
woff2_out.h
Go to the documentation of this file.
1 // Copyright 2016 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // Output buffer for WOFF2 decompression.
16 
17 // Copyright 2016 Google Inc. All Rights Reserved.
18 //
19 // Licensed under the Apache License, Version 2.0 (the "License");
20 // you may not use this file except in compliance with the License.
21 // You may obtain a copy of the License at
22 //
23 // http://www.apache.org/licenses/LICENSE-2.0
24 //
25 // Unless required by applicable law or agreed to in writing, software
26 // distributed under the License is distributed on an "AS IS" BASIS,
27 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 // See the License for the specific language governing permissions and
29 // limitations under the License.
30 //
31 // Output buffer for WOFF2 decompression.
32 
33 #ifndef WOFF2_WOFF2_OUT_H_
34 #define WOFF2_WOFF2_OUT_H_
35 
36 #include <algorithm>
37 #include <cstring>
38 #include <memory>
39 #include <string>
40 #include "./port.h"
41 
42 namespace woff2 {
43 
44 // Suggested max size for output.
45 const size_t kDefaultMaxSize = 30 * 1024 * 1024;
46 
47 using std::string;
48 
49 
59 class WOFF2Out {
60  public:
61  virtual ~WOFF2Out(void) {}
62 
63  // Append n bytes of data from buf.
64  // Return true if all written, false otherwise.
65  virtual bool Write(const void *buf, size_t n) = 0;
66 
67  // Write n bytes of data from buf at offset.
68  // Return true if all written, false otherwise.
69  virtual bool Write(const void *buf, size_t offset, size_t n) = 0;
70 
71  virtual size_t Size() = 0;
72 };
73 
77 class WOFF2StringOut : public WOFF2Out {
78  public:
79  // Create a writer that writes its data to buf.
80  // buf->size() will grow to at most max_size
81  // buf may be sized (e.g. using EstimateWOFF2FinalSize) or empty.
82  explicit WOFF2StringOut(string* buf);
83 
84  bool Write(const void *buf, size_t n) override;
85  bool Write(const void *buf, size_t offset, size_t n) override;
86  size_t Size() override { return offset_; }
87  size_t MaxSize() { return max_size_; }
88  void SetMaxSize(size_t max_size);
89  private:
90  string* buf_;
91  size_t max_size_;
92  size_t offset_;
93 };
94 
98 class WOFF2MemoryOut : public WOFF2Out {
99  public:
100  // Create a writer that writes its data to buf.
101  WOFF2MemoryOut(uint8_t* buf, size_t buf_size);
102 
103  bool Write(const void *buf, size_t n) override;
104  bool Write(const void *buf, size_t offset, size_t n) override;
105  size_t Size() override { return offset_; }
106  private:
107  uint8_t* buf_;
108  size_t buf_size_;
109  size_t offset_;
110 };
111 
112 } // namespace woff2
113 
114 #endif // WOFF2_WOFF2_OUT_H_
size_t Size() override
Definition: woff2_out.h:105
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: gl2ext.h:134
size_t MaxSize()
Definition: woff2_out.h:87
size_t Size() override
Definition: woff2_out.h:86
EGLStreamKHR EGLint n
Definition: eglext.h:984
EGLStreamKHR EGLint EGLint offset
Definition: eglext.h:984
unsigned char uint8_t
Definition: ptypes.h:89
virtual ~WOFF2Out(void)
Definition: woff2_out.h:61
const size_t kDefaultMaxSize
Definition: woff2_out.h:45
Definition: woff2_out.h:59
GLsizei const GLchar *const * string
Definition: gl2.h:479
virtual size_t Size()=0
Definition: woff2_out.h:98
virtual bool Write(const void *buf, size_t n)=0
Definition: buffer.h:45
Definition: woff2_out.h:77