blob: 2348ac70964701174c1b4dc481584326590109b3 [file] [log] [blame]
bnccd5ec3c2019-08-14 13:50:46 -07001// Copyright (c) 2019 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// Utility methods to convert between absolute indexing (used in the dynamic
6// table), relative indexing used on the encoder stream, and relative indexing
7// and post-base indexing used on request streams (in header blocks). See:
8// https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#indexing
9// https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#relative-indexing
10// https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#post-base
11
12#ifndef QUICHE_QUIC_CORE_QPACK_QPACK_INDEX_CONVERSIONS_H_
13#define QUICHE_QUIC_CORE_QPACK_QPACK_INDEX_CONVERSIONS_H_
14
15#include <cstdint>
16
bncfd3ee302019-08-16 04:40:46 -070017#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
18
bnccd5ec3c2019-08-14 13:50:46 -070019namespace quic {
20
21// Conversion functions used in the encoder do not check for overflow/underflow.
22// Since the maximum index is limited by maximum dynamic table capacity
23// (represented on uint64_t) divided by minimum header field size (defined to be
24// 32 bytes), overflow is not possible. The caller is responsible for providing
25// input that does not underflow.
26
bncfd3ee302019-08-16 04:40:46 -070027QUIC_EXPORT_PRIVATE uint64_t
28QpackAbsoluteIndexToEncoderStreamRelativeIndex(uint64_t absolute_index,
29 uint64_t inserted_entry_count);
bnccd5ec3c2019-08-14 13:50:46 -070030
bncfd3ee302019-08-16 04:40:46 -070031QUIC_EXPORT_PRIVATE uint64_t
32QpackAbsoluteIndexToRequestStreamRelativeIndex(uint64_t absolute_index,
33 uint64_t base);
bnccd5ec3c2019-08-14 13:50:46 -070034
35// Conversion functions used in the decoder operate on input received from the
36// network. These functions return false on overflow or underflow.
37
bncfd3ee302019-08-16 04:40:46 -070038QUIC_EXPORT_PRIVATE bool QpackEncoderStreamRelativeIndexToAbsoluteIndex(
bnccd5ec3c2019-08-14 13:50:46 -070039 uint64_t relative_index,
40 uint64_t inserted_entry_count,
41 uint64_t* absolute_index);
42
bncfd3ee302019-08-16 04:40:46 -070043// On success, |*absolute_index| is guaranteed to be strictly less than
44// std::numeric_limits<uint64_t>::max().
45QUIC_EXPORT_PRIVATE bool QpackRequestStreamRelativeIndexToAbsoluteIndex(
46 uint64_t relative_index,
47 uint64_t base,
48 uint64_t* absolute_index);
bnccd5ec3c2019-08-14 13:50:46 -070049
50// On success, |*absolute_index| is guaranteed to be strictly less than
51// std::numeric_limits<uint64_t>::max().
bncfd3ee302019-08-16 04:40:46 -070052QUIC_EXPORT_PRIVATE bool QpackPostBaseIndexToAbsoluteIndex(
53 uint64_t post_base_index,
54 uint64_t base,
55 uint64_t* absolute_index);
bnccd5ec3c2019-08-14 13:50:46 -070056
57} // namespace quic
58
59#endif // QUICHE_QUIC_CORE_QPACK_QPACK_INDEX_CONVERSIONS_H_