blob: a6597dbfb61b58dc56db524696f8d5e169f8735c [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
bnc641ace72020-01-21 12:24:57 -080014#include "net/third_party/quiche/src/common/platform/api/quiche_export.h"
bnc74646d12019-12-13 09:21:19 -080015#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.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().
21QUICHE_EXPORT_PRIVATE size_t HuffmanSize(quiche::QuicheStringPiece 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
bncc2fce352020-10-05 07:24:22 -070025// 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
bncdaf57072020-10-01 15:28:59 -070027// reusing the same string object across multiple invocations.
bnc641ace72020-01-21 12:24:57 -080028QUICHE_EXPORT_PRIVATE void HuffmanEncode(quiche::QuicheStringPiece plain,
bncdaf57072020-10-01 15:28:59 -070029 size_t encoded_size,
bnc641ace72020-01-21 12:24:57 -080030 std::string* huffman);
QUICHE teamfd50a402018-12-07 22:54:05 -050031
bnc0f73a762020-10-02 13:51:02 -070032// Encode |input| with the Huffman encoding defined RFC7541, used in HPACK and
bncc2fce352020-10-05 07:24:22 -070033// QPACK. |encoded_size| must be the value returned by HuffmanSize().
bnc0f73a762020-10-02 13:51:02 -070034// Appends the result to the end of |*output|.
35QUICHE_EXPORT_PRIVATE void HuffmanEncodeFast(quiche::QuicheStringPiece input,
36 size_t encoded_size,
37 std::string* output);
38
QUICHE teamfd50a402018-12-07 22:54:05 -050039} // namespace http2
40
41#endif // QUICHE_HTTP2_HPACK_HUFFMAN_HPACK_HUFFMAN_ENCODER_H_