| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/spdy/hpack/hpack_entry.h" | 5 #include "net/spdy/hpack/hpack_entry.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 | 11 |
| 12 using base::StringPiece; | 12 using base::StringPiece; |
| 13 | 13 |
| 14 const size_t HpackEntry::kSizeOverhead = 32; | 14 const size_t HpackEntry::kSizeOverhead = 32; |
| 15 | 15 |
| 16 HpackEntry::HpackEntry(StringPiece name, | 16 HpackEntry::HpackEntry(StringPiece name, |
| 17 StringPiece value, | 17 StringPiece value, |
| 18 bool is_static, | 18 bool is_static, |
| 19 size_t insertion_index) | 19 size_t insertion_index) |
| 20 : name_(name.data(), name.size()), | 20 : name_(name.data(), name.size()), |
| 21 value_(value.data(), value.size()), | 21 value_(value.data(), value.size()), |
| 22 name_ref_(name_), |
| 23 value_ref_(value_), |
| 22 insertion_index_(insertion_index), | 24 insertion_index_(insertion_index), |
| 23 type_(is_static ? STATIC : DYNAMIC) {} | 25 type_(is_static ? STATIC : DYNAMIC) {} |
| 24 | 26 |
| 25 HpackEntry::HpackEntry(StringPiece name, StringPiece value) | 27 HpackEntry::HpackEntry(StringPiece name, StringPiece value) |
| 26 : name_(name.data(), name.size()), | 28 : name_ref_(name), value_ref_(value), insertion_index_(0), type_(LOOKUP) {} |
| 27 value_(value.data(), value.size()), | |
| 28 insertion_index_(0), | |
| 29 type_(LOOKUP) {} | |
| 30 | 29 |
| 31 HpackEntry::HpackEntry() : insertion_index_(0), type_(LOOKUP) {} | 30 HpackEntry::HpackEntry() : insertion_index_(0), type_(LOOKUP) {} |
| 32 | 31 |
| 32 HpackEntry::HpackEntry(const HpackEntry& other) |
| 33 : insertion_index_(other.insertion_index_), type_(other.type_) { |
| 34 if (type_ == LOOKUP) { |
| 35 name_ref_ = other.name_ref_; |
| 36 value_ref_ = other.value_ref_; |
| 37 } else { |
| 38 name_ = other.name_; |
| 39 value_ = other.value_; |
| 40 name_ref_.set(name_.data(), name_.size()); |
| 41 value_ref_.set(value_.data(), value_.size()); |
| 42 } |
| 43 } |
| 44 |
| 45 HpackEntry& HpackEntry::operator=(const HpackEntry& other) { |
| 46 insertion_index_ = other.insertion_index_; |
| 47 type_ = other.type_; |
| 48 if (type_ == LOOKUP) { |
| 49 name_ref_ = other.name_ref_; |
| 50 value_ref_ = other.value_ref_; |
| 51 return *this; |
| 52 } |
| 53 name_ = other.name_; |
| 54 value_ = other.value_; |
| 55 name_ref_.set(name_.data(), name_.size()); |
| 56 value_ref_.set(value_.data(), value_.size()); |
| 57 return *this; |
| 58 } |
| 59 |
| 33 HpackEntry::~HpackEntry() {} | 60 HpackEntry::~HpackEntry() {} |
| 34 | 61 |
| 35 // static | 62 // static |
| 36 size_t HpackEntry::Size(StringPiece name, StringPiece value) { | 63 size_t HpackEntry::Size(StringPiece name, StringPiece value) { |
| 37 return name.size() + value.size() + kSizeOverhead; | 64 return name.size() + value.size() + kSizeOverhead; |
| 38 } | 65 } |
| 66 |
| 39 size_t HpackEntry::Size() const { | 67 size_t HpackEntry::Size() const { |
| 40 return Size(name(), value()); | 68 return Size(name(), value()); |
| 41 } | 69 } |
| 42 | 70 |
| 43 std::string HpackEntry::GetDebugString() const { | 71 std::string HpackEntry::GetDebugString() const { |
| 44 return "{ name: \"" + name_ + "\", value: \"" + value_ + "\", " + | 72 return "{ name: \"" + name_ref_.as_string() + "\", value: \"" + |
| 45 (IsStatic() ? "static" : "dynamic") + " }"; | 73 value_ref_.as_string() + "\", index: " + |
| 74 base::SizeTToString(insertion_index_) + |
| 75 (IsStatic() ? " static" : (IsLookup() ? " lookup" : " dynamic")) + |
| 76 " }"; |
| 46 } | 77 } |
| 47 | 78 |
| 48 } // namespace net | 79 } // namespace net |
| OLD | NEW |