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 17 #include "quiche/quic/platform/api/quic_export.h" 18 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 27 QUICHE_EXPORT uint64_t QpackAbsoluteIndexToEncoderStreamRelativeIndex( 28 uint64_t absolute_index, uint64_t inserted_entry_count); 29 30 QUICHE_EXPORT uint64_t QpackAbsoluteIndexToRequestStreamRelativeIndex( 31 uint64_t absolute_index, uint64_t base); 32 33 // Conversion functions used in the decoder operate on input received from the 34 // network. These functions return false on overflow or underflow. 35 36 QUICHE_EXPORT bool QpackEncoderStreamRelativeIndexToAbsoluteIndex( 37 uint64_t relative_index, uint64_t inserted_entry_count, 38 uint64_t* absolute_index); 39 40 // On success, |*absolute_index| is guaranteed to be strictly less than 41 // std::numeric_limits<uint64_t>::max(). 42 QUICHE_EXPORT bool QpackRequestStreamRelativeIndexToAbsoluteIndex( 43 uint64_t relative_index, uint64_t base, uint64_t* absolute_index); 44 45 // On success, |*absolute_index| is guaranteed to be strictly less than 46 // std::numeric_limits<uint64_t>::max(). 47 QUICHE_EXPORT bool QpackPostBaseIndexToAbsoluteIndex(uint64_t post_base_index, 48 uint64_t base, 49 uint64_t* absolute_index); 50 51 } // namespace quic 52 53 #endif // QUICHE_QUIC_CORE_QPACK_QPACK_INDEX_CONVERSIONS_H_ 54