OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/spdy/hpack/hpack_entry.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/strings/string_number_conversions.h" | |
9 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" | |
10 | |
11 namespace net { | |
12 | |
13 const size_t HpackEntry::kSizeOverhead = 32; | |
14 | |
15 HpackEntry::HpackEntry(SpdyStringPiece name, | |
16 SpdyStringPiece value, | |
17 bool is_static, | |
18 size_t insertion_index) | |
19 : name_(name.data(), name.size()), | |
20 value_(value.data(), value.size()), | |
21 name_ref_(name_), | |
22 value_ref_(value_), | |
23 insertion_index_(insertion_index), | |
24 type_(is_static ? STATIC : DYNAMIC), | |
25 time_added_(0) {} | |
26 | |
27 HpackEntry::HpackEntry(SpdyStringPiece name, SpdyStringPiece value) | |
28 : name_ref_(name), | |
29 value_ref_(value), | |
30 insertion_index_(0), | |
31 type_(LOOKUP), | |
32 time_added_(0) {} | |
33 | |
34 HpackEntry::HpackEntry() : insertion_index_(0), type_(LOOKUP), time_added_(0) {} | |
35 | |
36 HpackEntry::HpackEntry(const HpackEntry& other) | |
37 : insertion_index_(other.insertion_index_), | |
38 type_(other.type_), | |
39 time_added_(0) { | |
40 if (type_ == LOOKUP) { | |
41 name_ref_ = other.name_ref_; | |
42 value_ref_ = other.value_ref_; | |
43 } else { | |
44 name_ = other.name_; | |
45 value_ = other.value_; | |
46 name_ref_ = SpdyStringPiece(name_.data(), name_.size()); | |
47 value_ref_ = SpdyStringPiece(value_.data(), value_.size()); | |
48 } | |
49 } | |
50 | |
51 HpackEntry& HpackEntry::operator=(const HpackEntry& other) { | |
52 insertion_index_ = other.insertion_index_; | |
53 type_ = other.type_; | |
54 if (type_ == LOOKUP) { | |
55 name_ref_ = other.name_ref_; | |
56 value_ref_ = other.value_ref_; | |
57 return *this; | |
58 } | |
59 name_ = other.name_; | |
60 value_ = other.value_; | |
61 name_ref_ = SpdyStringPiece(name_.data(), name_.size()); | |
62 value_ref_ = SpdyStringPiece(value_.data(), value_.size()); | |
63 return *this; | |
64 } | |
65 | |
66 HpackEntry::~HpackEntry() {} | |
67 | |
68 // static | |
69 size_t HpackEntry::Size(SpdyStringPiece name, SpdyStringPiece value) { | |
70 return name.size() + value.size() + kSizeOverhead; | |
71 } | |
72 | |
73 size_t HpackEntry::Size() const { | |
74 return Size(name(), value()); | |
75 } | |
76 | |
77 SpdyString HpackEntry::GetDebugString() const { | |
78 return "{ name: \"" + SpdyString(name_ref_) + "\", value: \"" + | |
79 SpdyString(value_ref_) + | |
80 "\", index: " + base::SizeTToString(insertion_index_) + | |
81 (IsStatic() ? " static" : (IsLookup() ? " lookup" : " dynamic")) + | |
82 " }"; | |
83 } | |
84 | |
85 size_t HpackEntry::EstimateMemoryUsage() const { | |
86 return SpdyEstimateMemoryUsage(name_) + SpdyEstimateMemoryUsage(value_); | |
87 } | |
88 | |
89 } // namespace net | |
OLD | NEW |