QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef QUICHE_HTTP2_HPACK_HUFFMAN_HPACK_HUFFMAN_ENCODER_H_ |
| 6 | #define QUICHE_HTTP2_HPACK_HUFFMAN_HPACK_HUFFMAN_ENCODER_H_ |
| 7 | |
| 8 | // Functions supporting the encoding of strings using the HPACK-defined Huffman |
| 9 | // table. |
| 10 | |
| 11 | #include <cstddef> // For size_t |
bnc | 4790400 | 2019-08-16 11:49:48 -0700 | [diff] [blame] | 12 | #include <string> |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 13 | |
vasilvv | 54011f2 | 2020-10-12 03:13:48 -0700 | [diff] [blame] | 14 | #include "absl/strings/string_view.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 15 | #include "common/platform/api/quiche_export.h" |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 16 | |
| 17 | namespace http2 { |
| 18 | |
| 19 | // Returns the size of the Huffman encoding of |plain|, which may be greater |
bnc | c2fce35 | 2020-10-05 07:24:22 -0700 | [diff] [blame] | 20 | // than plain.size(). |
vasilvv | 54011f2 | 2020-10-12 03:13:48 -0700 | [diff] [blame] | 21 | QUICHE_EXPORT_PRIVATE size_t HuffmanSize(absl::string_view plain); |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 22 | |
bnc | daf5707 | 2020-10-01 15:28:59 -0700 | [diff] [blame] | 23 | // Encode the plain text string |plain| with the Huffman encoding defined in the |
| 24 | // HPACK RFC, 7541. |encoded_size| is used to pre-allocate storage and it |
bnc | f1b46eb | 2020-10-08 08:02:57 -0700 | [diff] [blame] | 25 | // should be the value returned by HuffmanSize(). Appends the result to |
| 26 | // |*huffman|. |
vasilvv | 54011f2 | 2020-10-12 03:13:48 -0700 | [diff] [blame] | 27 | QUICHE_EXPORT_PRIVATE void HuffmanEncode(absl::string_view plain, |
bnc | daf5707 | 2020-10-01 15:28:59 -0700 | [diff] [blame] | 28 | size_t encoded_size, |
bnc | 641ace7 | 2020-01-21 12:24:57 -0800 | [diff] [blame] | 29 | std::string* huffman); |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 30 | |
bnc | 0f73a76 | 2020-10-02 13:51:02 -0700 | [diff] [blame] | 31 | // Encode |input| with the Huffman encoding defined RFC7541, used in HPACK and |
bnc | c2fce35 | 2020-10-05 07:24:22 -0700 | [diff] [blame] | 32 | // QPACK. |encoded_size| must be the value returned by HuffmanSize(). |
bnc | 0f73a76 | 2020-10-02 13:51:02 -0700 | [diff] [blame] | 33 | // Appends the result to the end of |*output|. |
vasilvv | 54011f2 | 2020-10-12 03:13:48 -0700 | [diff] [blame] | 34 | QUICHE_EXPORT_PRIVATE void HuffmanEncodeFast(absl::string_view input, |
bnc | 0f73a76 | 2020-10-02 13:51:02 -0700 | [diff] [blame] | 35 | size_t encoded_size, |
| 36 | std::string* output); |
| 37 | |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 38 | } // namespace http2 |
| 39 | |
| 40 | #endif // QUICHE_HTTP2_HPACK_HUFFMAN_HPACK_HUFFMAN_ENCODER_H_ |