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 12 #include <string> 13 14 #include "absl/strings/string_view.h" 15 #include "quiche/common/platform/api/quiche_export.h" 16 17 namespace http2 { 18 19 // Returns the size of the Huffman encoding of |plain|, which may be greater 20 // than plain.size(). 21 QUICHE_EXPORT size_t HuffmanSize(absl::string_view plain); 22 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 25 // should be the value returned by HuffmanSize(). Appends the result to 26 // |*huffman|. 27 QUICHE_EXPORT void HuffmanEncode(absl::string_view plain, size_t encoded_size, 28 std::string* huffman); 29 30 // Encode |input| with the Huffman encoding defined RFC7541, used in HPACK and 31 // QPACK. |encoded_size| must be the value returned by HuffmanSize(). 32 // Appends the result to the end of |*output|. 33 QUICHE_EXPORT void HuffmanEncodeFast(absl::string_view input, 34 size_t encoded_size, std::string* output); 35 36 } // namespace http2 37 38 #endif // QUICHE_HTTP2_HPACK_HUFFMAN_HPACK_HUFFMAN_ENCODER_H_ 39