bnc | cd5ec3c | 2019-08-14 13:50:46 -0700 | [diff] [blame] | 1 | // 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 | |
bnc | fd3ee30 | 2019-08-16 04:40:46 -0700 | [diff] [blame] | 17 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
| 18 | |
bnc | cd5ec3c | 2019-08-14 13:50:46 -0700 | [diff] [blame] | 19 | namespace 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 | |
bnc | fd3ee30 | 2019-08-16 04:40:46 -0700 | [diff] [blame] | 27 | QUIC_EXPORT_PRIVATE uint64_t |
| 28 | QpackAbsoluteIndexToEncoderStreamRelativeIndex(uint64_t absolute_index, |
| 29 | uint64_t inserted_entry_count); |
bnc | cd5ec3c | 2019-08-14 13:50:46 -0700 | [diff] [blame] | 30 | |
bnc | fd3ee30 | 2019-08-16 04:40:46 -0700 | [diff] [blame] | 31 | QUIC_EXPORT_PRIVATE uint64_t |
| 32 | QpackAbsoluteIndexToRequestStreamRelativeIndex(uint64_t absolute_index, |
| 33 | uint64_t base); |
bnc | cd5ec3c | 2019-08-14 13:50:46 -0700 | [diff] [blame] | 34 | |
| 35 | // Conversion functions used in the decoder operate on input received from the |
| 36 | // network. These functions return false on overflow or underflow. |
| 37 | |
bnc | fd3ee30 | 2019-08-16 04:40:46 -0700 | [diff] [blame] | 38 | QUIC_EXPORT_PRIVATE bool QpackEncoderStreamRelativeIndexToAbsoluteIndex( |
bnc | cd5ec3c | 2019-08-14 13:50:46 -0700 | [diff] [blame] | 39 | uint64_t relative_index, |
| 40 | uint64_t inserted_entry_count, |
| 41 | uint64_t* absolute_index); |
| 42 | |
bnc | fd3ee30 | 2019-08-16 04:40:46 -0700 | [diff] [blame] | 43 | // On success, |*absolute_index| is guaranteed to be strictly less than |
| 44 | // std::numeric_limits<uint64_t>::max(). |
| 45 | QUIC_EXPORT_PRIVATE bool QpackRequestStreamRelativeIndexToAbsoluteIndex( |
| 46 | uint64_t relative_index, |
| 47 | uint64_t base, |
| 48 | uint64_t* absolute_index); |
bnc | cd5ec3c | 2019-08-14 13:50:46 -0700 | [diff] [blame] | 49 | |
| 50 | // On success, |*absolute_index| is guaranteed to be strictly less than |
| 51 | // std::numeric_limits<uint64_t>::max(). |
bnc | fd3ee30 | 2019-08-16 04:40:46 -0700 | [diff] [blame] | 52 | QUIC_EXPORT_PRIVATE bool QpackPostBaseIndexToAbsoluteIndex( |
| 53 | uint64_t post_base_index, |
| 54 | uint64_t base, |
| 55 | uint64_t* absolute_index); |
bnc | cd5ec3c | 2019-08-14 13:50:46 -0700 | [diff] [blame] | 56 | |
| 57 | } // namespace quic |
| 58 | |
| 59 | #endif // QUICHE_QUIC_CORE_QPACK_QPACK_INDEX_CONVERSIONS_H_ |