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