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

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

Powered by Google App Engine
This is Rietveld 408576698