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

Unified Diff: net/spdy/hpack_entry.h

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_encoding_context_test.cc ('k') | net/spdy/hpack_entry.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/hpack_entry.h
diff --git a/net/spdy/hpack_entry.h b/net/spdy/hpack_entry.h
new file mode 100644
index 0000000000000000000000000000000000000000..d281b3bfea0714f65b1b205356d62c0cbee96f8a
--- /dev/null
+++ b/net/spdy/hpack_entry.h
@@ -0,0 +1,103 @@
+// 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.
+
+#ifndef NET_SPDY_HPACK_ENTRY_H_
+#define NET_SPDY_HPACK_ENTRY_H_
+
+#include <cstddef>
+#include <deque>
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/macros.h"
+#include "base/strings/string_piece.h"
+#include "net/base/net_export.h"
+
+namespace net {
+
+// All section references below are to
+// http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-04
+// .
+
+// A structure for an entry in the header table (3.1.2) and the
+// reference set (3.1.3). This structure also keeps track of how many
+// times the entry has been 'touched', which is useful for both
+// encoding and decoding.
+class NET_EXPORT_PRIVATE HpackEntry {
+ public:
+ // The constant amount added to name().size() and value().size() to
+ // get the size of an HpackEntry as defined in 3.3.1.
+ static const uint32 kSizeOverhead;
+
+ // The constant returned by touch_count() if an entry hasn't been
+ // touched (which is distinct from an entry having a touch count of
+ // 0).
+ //
+ // TODO(akalin): The distinction between untouched and having a
+ // touch count of 0 is confusing. Think of a better way to represent
+ // this state.
+ static const uint32 kUntouched;
+
+ // Creates an entry with empty name a value. Only defined so that
+ // entries can be stored in STL containers.
+ HpackEntry();
+
+ // Creates an entry with a copy is made of the given name and value.
+ //
+ // TODO(akalin): Add option to not make a copy (for static table
+ // entries).
+ HpackEntry(base::StringPiece name, base::StringPiece value);
+
+ // Copy constructor and assignment operator welcome.
+
+ // The name() and value() StringPieces have the same lifetime as
+ // this entry.
+
+ base::StringPiece name() const { return base::StringPiece(name_); }
+ base::StringPiece value() const { return base::StringPiece(value_); }
+
+ // Returns whether or not this entry is in the reference set.
+ bool IsReferenced() const;
+
+ // Returns how many touches this entry has, or kUntouched if this
+ // entry hasn't been touched at all. The meaning of the touch count
+ // is defined by whatever is calling
+ // AddTouchCount()/ClearTouchCount() (i.e., the encoder or decoder).
+ uint32 TouchCount() const;
+
+ // Returns the size of an entry as defined in 3.3.1. The returned
+ // value may not necessarily fit in 32 bits.
+ size_t Size() const;
+
+ std::string GetDebugString() const;
+
+ // Returns whether this entry has the same name, value, referenced
+ // state, and touch count as the given one.
+ bool Equals(const HpackEntry& other) const;
+
+ void SetReferenced(bool referenced);
+
+ // Adds the given number of touches to this entry (see
+ // TouchCount()). The total number of touches must not exceed 2^31 -
+ // 2. It is guaranteed that this entry's touch count will not equal
+ // kUntouched after this function is called (even if touch_count ==
+ // 0).
+ void AddTouches(uint32 additional_touch_count);
+
+ // Sets the touch count of this entry to kUntouched.
+ void ClearTouches();
+
+ private:
+ std::string name_;
+ std::string value_;
+
+ // The high bit stores 'referenced' and the rest stores the touch
+ // count.
+ uint32 referenced_and_touch_count_;
+};
+
+} // namespace net
+
+#endif // NET_SPDY_HPACK_ENTRY_H_
« no previous file with comments | « net/spdy/hpack_encoding_context_test.cc ('k') | net/spdy/hpack_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698