Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Unified Diff: net/spdy/hpack_entry.cc

Issue 138243003: Implement basic classes for HPACK (HTTP/2 compression) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding license to new HPACK sources. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/spdy/hpack_entry.h ('k') | net/spdy/hpack_entry_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/hpack_entry.cc
diff --git a/net/spdy/hpack_entry.cc b/net/spdy/hpack_entry.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d90926c39033f5127f7dfd2595dbe9535245fec1
--- /dev/null
+++ b/net/spdy/hpack_entry.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/spdy/hpack_entry.h"
+
+#include "base/logging.h"
+#include "base/strings/string_number_conversions.h"
+#include "net/spdy/hpack_string_util.h"
+
+namespace net {
+
+namespace {
+
+const uint32 kReferencedMask = 0x80000000;
+const uint32 kTouchCountMask = 0x7fffffff;
+
+} // namespace
+
+const uint32 HpackEntry::kSizeOverhead = 32;
+
+const uint32 HpackEntry::kUntouched = 0x7fffffff;
+
+HpackEntry::HpackEntry() : referenced_and_touch_count_(kUntouched) {}
+
+HpackEntry::HpackEntry(base::StringPiece name, base::StringPiece value)
+ : name_(name.as_string()),
+ value_(value.as_string()),
+ referenced_and_touch_count_(kUntouched) {}
+
+bool HpackEntry::IsReferenced() const {
+ return ((referenced_and_touch_count_ & kReferencedMask) != 0);
+}
+
+uint32 HpackEntry::TouchCount() const {
+ return referenced_and_touch_count_ & kTouchCountMask;
+}
+
+size_t HpackEntry::Size() const {
+ return name_.size() + value_.size() + kSizeOverhead;
+}
+
+std::string HpackEntry::GetDebugString() const {
+ const char* is_referenced_str = (IsReferenced() ? "true" : "false");
+ std::string touch_count_str = "(untouched)";
+ if (TouchCount() != kUntouched)
+ touch_count_str = base::IntToString(TouchCount());
+ return "{ name: \"" + name_ + "\", value: \"" + value_ +
+ "\", referenced: " + is_referenced_str + ", touch_count: " +
+ touch_count_str + " }";
+}
+
+bool HpackEntry::Equals(const HpackEntry& other) const {
+ return
+ StringPiecesEqualConstantTime(name_, other.name_) &&
+ StringPiecesEqualConstantTime(value_, other.value_) &&
+ (referenced_and_touch_count_ == other.referenced_and_touch_count_);
+}
+
+void HpackEntry::SetReferenced(bool referenced) {
+ referenced_and_touch_count_ &= kTouchCountMask;
+ if (referenced)
+ referenced_and_touch_count_ |= kReferencedMask;
+}
+
+void HpackEntry::AddTouches(uint32 additional_touch_count) {
+ uint32 new_touch_count = TouchCount();
+ if (new_touch_count == kUntouched)
+ new_touch_count = 0;
+ new_touch_count += additional_touch_count;
+ DCHECK_LT(new_touch_count, kUntouched);
+ referenced_and_touch_count_ &= kReferencedMask;
+ referenced_and_touch_count_ |= new_touch_count;
+}
+
+void HpackEntry::ClearTouches() {
+ referenced_and_touch_count_ &= kReferencedMask;
+ referenced_and_touch_count_ |= kUntouched;
+}
+
+} // namespace net
« no previous file with comments | « net/spdy/hpack_entry.h ('k') | net/spdy/hpack_entry_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698