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 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_index_conversions.h" |
| 6 | |
| 7 | #include <limits> |
| 8 | |
| 9 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
| 10 | |
| 11 | namespace quic { |
| 12 | |
| 13 | uint64_t QpackAbsoluteIndexToEncoderStreamRelativeIndex( |
| 14 | uint64_t absolute_index, |
| 15 | uint64_t inserted_entry_count) { |
| 16 | DCHECK_LT(absolute_index, inserted_entry_count); |
| 17 | |
| 18 | return inserted_entry_count - absolute_index - 1; |
| 19 | } |
| 20 | |
| 21 | uint64_t QpackAbsoluteIndexToRequestStreamRelativeIndex(uint64_t absolute_index, |
| 22 | uint64_t base) { |
| 23 | DCHECK_LT(absolute_index, base); |
| 24 | |
| 25 | return base - absolute_index - 1; |
| 26 | } |
| 27 | |
| 28 | bool QpackEncoderStreamRelativeIndexToAbsoluteIndex( |
| 29 | uint64_t relative_index, |
| 30 | uint64_t inserted_entry_count, |
| 31 | uint64_t* absolute_index) { |
| 32 | if (relative_index >= inserted_entry_count) { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | *absolute_index = inserted_entry_count - relative_index - 1; |
| 37 | return true; |
| 38 | } |
| 39 | |
| 40 | bool QpackRequestStreamRelativeIndexToAbsoluteIndex(uint64_t relative_index, |
| 41 | uint64_t base, |
| 42 | uint64_t* absolute_index) { |
| 43 | if (relative_index >= base) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | *absolute_index = base - relative_index - 1; |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | bool QpackPostBaseIndexToAbsoluteIndex(uint64_t post_base_index, |
| 52 | uint64_t base, |
| 53 | uint64_t* absolute_index) { |
| 54 | if (post_base_index >= std::numeric_limits<uint64_t>::max() - base) { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | *absolute_index = base + post_base_index; |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | } // namespace quic |