OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 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/spdy/hpack_entry.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "net/spdy/hpack_string_util.h" |
| 10 |
| 11 namespace net { |
| 12 |
| 13 namespace { |
| 14 |
| 15 const uint32 kReferencedMask = 0x80000000; |
| 16 const uint32 kTouchCountMask = 0x7fffffff; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 const uint32 HpackEntry::kSizeOverhead = 32; |
| 21 |
| 22 const uint32 HpackEntry::kUntouched = 0x7fffffff; |
| 23 |
| 24 HpackEntry::HpackEntry() : referenced_and_touch_count_(kUntouched) {} |
| 25 |
| 26 HpackEntry::HpackEntry(base::StringPiece name, base::StringPiece value) |
| 27 : name_(name.as_string()), |
| 28 value_(value.as_string()), |
| 29 referenced_and_touch_count_(kUntouched) {} |
| 30 |
| 31 bool HpackEntry::IsReferenced() const { |
| 32 return ((referenced_and_touch_count_ & kReferencedMask) != 0); |
| 33 } |
| 34 |
| 35 uint32 HpackEntry::TouchCount() const { |
| 36 return referenced_and_touch_count_ & kTouchCountMask; |
| 37 } |
| 38 |
| 39 size_t HpackEntry::Size() const { |
| 40 return name_.size() + value_.size() + kSizeOverhead; |
| 41 } |
| 42 |
| 43 std::string HpackEntry::GetDebugString() const { |
| 44 const char* is_referenced_str = (IsReferenced() ? "true" : "false"); |
| 45 std::string touch_count_str = "(untouched)"; |
| 46 if (TouchCount() != kUntouched) |
| 47 touch_count_str = base::IntToString(TouchCount()); |
| 48 return "{ name: \"" + name_ + "\", value: \"" + value_ + |
| 49 "\", referenced: " + is_referenced_str + ", touch_count: " + |
| 50 touch_count_str + " }"; |
| 51 } |
| 52 |
| 53 bool HpackEntry::Equals(const HpackEntry& other) const { |
| 54 return |
| 55 StringPiecesEqualConstantTime(name_, other.name_) && |
| 56 StringPiecesEqualConstantTime(value_, other.value_) && |
| 57 (referenced_and_touch_count_ == other.referenced_and_touch_count_); |
| 58 } |
| 59 |
| 60 void HpackEntry::SetReferenced(bool referenced) { |
| 61 referenced_and_touch_count_ &= kTouchCountMask; |
| 62 if (referenced) |
| 63 referenced_and_touch_count_ |= kReferencedMask; |
| 64 } |
| 65 |
| 66 void HpackEntry::AddTouches(uint32 additional_touch_count) { |
| 67 uint32 new_touch_count = TouchCount(); |
| 68 if (new_touch_count == kUntouched) |
| 69 new_touch_count = 0; |
| 70 new_touch_count += additional_touch_count; |
| 71 DCHECK_LT(new_touch_count, kUntouched); |
| 72 referenced_and_touch_count_ &= kReferencedMask; |
| 73 referenced_and_touch_count_ |= new_touch_count; |
| 74 } |
| 75 |
| 76 void HpackEntry::ClearTouches() { |
| 77 referenced_and_touch_count_ &= kReferencedMask; |
| 78 referenced_and_touch_count_ |= kUntouched; |
| 79 } |
| 80 |
| 81 } // namespace net |
OLD | NEW |