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 | |
bnc | 641ace7 | 2020-01-21 12:24:57 -0800 | [diff] [blame] | 14 | #include "net/third_party/quiche/src/common/platform/api/quiche_export.h" |
bnc | 74646d1 | 2019-12-13 09:21:19 -0800 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.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(). |
| 21 | QUICHE_EXPORT_PRIVATE size_t HuffmanSize(quiche::QuicheStringPiece 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 | c2fce35 | 2020-10-05 07:24:22 -0700 | [diff] [blame^] | 25 | // should be the value returned by HuffmanSize(). |*huffman| does not have to |
| 26 | // be empty, it is cleared at the beginning of this function. This allows |
bnc | daf5707 | 2020-10-01 15:28:59 -0700 | [diff] [blame] | 27 | // reusing the same string object across multiple invocations. |
bnc | 641ace7 | 2020-01-21 12:24:57 -0800 | [diff] [blame] | 28 | QUICHE_EXPORT_PRIVATE void HuffmanEncode(quiche::QuicheStringPiece plain, |
bnc | daf5707 | 2020-10-01 15:28:59 -0700 | [diff] [blame] | 29 | size_t encoded_size, |
bnc | 641ace7 | 2020-01-21 12:24:57 -0800 | [diff] [blame] | 30 | std::string* huffman); |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 31 | |
bnc | 0f73a76 | 2020-10-02 13:51:02 -0700 | [diff] [blame] | 32 | // Encode |input| with the Huffman encoding defined RFC7541, used in HPACK and |
bnc | c2fce35 | 2020-10-05 07:24:22 -0700 | [diff] [blame^] | 33 | // QPACK. |encoded_size| must be the value returned by HuffmanSize(). |
bnc | 0f73a76 | 2020-10-02 13:51:02 -0700 | [diff] [blame] | 34 | // Appends the result to the end of |*output|. |
| 35 | QUICHE_EXPORT_PRIVATE void HuffmanEncodeFast(quiche::QuicheStringPiece input, |
| 36 | size_t encoded_size, |
| 37 | std::string* output); |
| 38 | |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 39 | } // namespace http2 |
| 40 | |
| 41 | #endif // QUICHE_HTTP2_HPACK_HUFFMAN_HPACK_HUFFMAN_ENCODER_H_ |