blob: a0ed8615129067385ecf4d543964c01a53458479 [file] [log] [blame]
QUICHE teamfd50a402018-12-07 22:54:05 -05001// 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
bnc47904002019-08-16 11:49:48 -070012#include <string>
QUICHE teamfd50a402018-12-07 22:54:05 -050013
vasilvv54011f22020-10-12 03:13:48 -070014#include "absl/strings/string_view.h"
QUICHE team5be974e2020-12-29 18:35:24 -050015#include "common/platform/api/quiche_export.h"
QUICHE teamfd50a402018-12-07 22:54:05 -050016
17namespace http2 {
18
19// Returns the size of the Huffman encoding of |plain|, which may be greater
bncc2fce352020-10-05 07:24:22 -070020// than plain.size().
vasilvv54011f22020-10-12 03:13:48 -070021QUICHE_EXPORT_PRIVATE size_t HuffmanSize(absl::string_view plain);
QUICHE teamfd50a402018-12-07 22:54:05 -050022
bncdaf57072020-10-01 15:28:59 -070023// 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
bncf1b46eb2020-10-08 08:02:57 -070025// should be the value returned by HuffmanSize(). Appends the result to
26// |*huffman|.
vasilvv54011f22020-10-12 03:13:48 -070027QUICHE_EXPORT_PRIVATE void HuffmanEncode(absl::string_view plain,
bncdaf57072020-10-01 15:28:59 -070028 size_t encoded_size,
bnc641ace72020-01-21 12:24:57 -080029 std::string* huffman);
QUICHE teamfd50a402018-12-07 22:54:05 -050030
bnc0f73a762020-10-02 13:51:02 -070031// Encode |input| with the Huffman encoding defined RFC7541, used in HPACK and
bncc2fce352020-10-05 07:24:22 -070032// QPACK. |encoded_size| must be the value returned by HuffmanSize().
bnc0f73a762020-10-02 13:51:02 -070033// Appends the result to the end of |*output|.
vasilvv54011f22020-10-12 03:13:48 -070034QUICHE_EXPORT_PRIVATE void HuffmanEncodeFast(absl::string_view input,
bnc0f73a762020-10-02 13:51:02 -070035 size_t encoded_size,
36 std::string* output);
37
QUICHE teamfd50a402018-12-07 22:54:05 -050038} // namespace http2
39
40#endif // QUICHE_HTTP2_HPACK_HUFFMAN_HPACK_HUFFMAN_ENCODER_H_