Revert of Update WV test license server config to use portable sdk server. (https...
[chromium-blink-merge.git] / net / spdy / hpack_entry.h
blob7b85109096d57bfe0a3f26b16ed8fccae099d015
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.
5 #ifndef NET_SPDY_HPACK_ENTRY_H_
6 #define NET_SPDY_HPACK_ENTRY_H_
8 #include <cstddef>
9 #include <deque>
10 #include <string>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/macros.h"
15 #include "base/strings/string_piece.h"
16 #include "net/base/net_export.h"
18 namespace net {
20 // All section references below are to
21 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-05
22 // .
24 // A structure for an entry in the header table (3.1.2) and the
25 // reference set (3.1.3). This structure also keeps track of how many
26 // times the entry has been 'touched', which is useful for both
27 // encoding and decoding.
28 class NET_EXPORT_PRIVATE HpackEntry {
29 public:
30 // The constant amount added to name().size() and value().size() to
31 // get the size of an HpackEntry as defined in 3.3.1.
32 static const uint32 kSizeOverhead;
34 // The constant returned by touch_count() if an entry hasn't been
35 // touched (which is distinct from an entry having a touch count of
36 // 0).
38 // TODO(akalin): The distinction between untouched and having a
39 // touch count of 0 is confusing. Think of a better way to represent
40 // this state.
41 static const uint32 kUntouched;
43 // Creates an entry with empty name a value. Only defined so that
44 // entries can be stored in STL containers.
45 HpackEntry();
47 // Creates an entry with a copy is made of the given name and value.
49 // TODO(akalin): Add option to not make a copy (for static table
50 // entries).
51 HpackEntry(base::StringPiece name, base::StringPiece value);
53 // Copy constructor and assignment operator welcome.
55 // The name() and value() StringPieces have the same lifetime as
56 // this entry.
58 base::StringPiece name() const { return base::StringPiece(name_); }
59 base::StringPiece value() const { return base::StringPiece(value_); }
61 // Returns whether or not this entry is in the reference set.
62 bool IsReferenced() const;
64 // Returns how many touches this entry has, or kUntouched if this
65 // entry hasn't been touched at all. The meaning of the touch count
66 // is defined by whatever is calling
67 // AddTouchCount()/ClearTouchCount() (i.e., the encoder or decoder).
68 uint32 TouchCount() const;
70 // Returns the size of an entry as defined in 3.3.1. The returned
71 // value may not necessarily fit in 32 bits.
72 size_t Size() const;
74 std::string GetDebugString() const;
76 // Returns whether this entry has the same name, value, referenced
77 // state, and touch count as the given one.
78 bool Equals(const HpackEntry& other) const;
80 void SetReferenced(bool referenced);
82 // Adds the given number of touches to this entry (see
83 // TouchCount()). The total number of touches must not exceed 2^31 -
84 // 2. It is guaranteed that this entry's touch count will not equal
85 // kUntouched after this function is called (even if touch_count ==
86 // 0).
87 void AddTouches(uint32 additional_touch_count);
89 // Sets the touch count of this entry to kUntouched.
90 void ClearTouches();
92 private:
93 std::string name_;
94 std::string value_;
96 // The high bit stores 'referenced' and the rest stores the touch
97 // count.
98 uint32 referenced_and_touch_count_;
101 } // namespace net
103 #endif // NET_SPDY_HPACK_ENTRY_H_