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_
12 #include "base/basictypes.h"
13 #include "base/macros.h"
14 #include "base/strings/string_piece.h"
15 #include "net/base/net_export.h"
17 // All section references below are to
18 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-07
22 // A structure for an entry in the header table (3.1.2) and the
23 // reference set (3.1.3).
24 class NET_EXPORT_PRIVATE HpackEntry {
26 // The constant amount added to name().size() and value().size() to
27 // get the size of an HpackEntry as defined in 3.3.1.
28 static const size_t kSizeOverhead;
30 // Creates an entry. Preconditions:
31 // - |is_static| captures whether this entry is a member of the static
32 // or dynamic header table.
33 // - |insertion_index| is this entry's index in the total set of entries ever
34 // inserted into the header table (including static entries).
36 // The combination of |is_static| and |insertion_index| allows an
37 // HpackEntryTable to determine the index of an HpackEntry in O(1) time.
38 HpackEntry(base::StringPiece name,
39 base::StringPiece value,
41 size_t insertion_index);
43 // Create a 'lookup' entry (only) suitable for querying a HpackEntrySet. The
44 // instance InsertionIndex() always returns 0 and IsLookup() returns true.
45 HpackEntry(base::StringPiece name, base::StringPiece value);
47 // Creates an entry with empty name and value. Only defined so that
48 // entries can be stored in STL containers.
53 const std::string& name() const { return name_; }
54 const std::string& value() const { return value_; }
56 // Returns whether this entry is a member of the static (as opposed to
58 bool IsStatic() const { return type_ == STATIC; }
60 // Returns whether this entry is a lookup-only entry.
61 bool IsLookup() const { return type_ == LOOKUP; }
63 // Returns and sets the state of the entry, or zero if never set.
64 // The semantics of |state| are specific to the encoder or decoder.
65 uint8 state() const { return state_; }
66 void set_state(uint8 state) { state_ = state; }
68 // Used to compute the entry's index in the header table.
69 size_t InsertionIndex() const { return insertion_index_; }
71 // Returns the size of an entry as defined in 3.3.1.
72 static size_t Size(base::StringPiece name, base::StringPiece value);
75 std::string GetDebugString() const;
84 // TODO(jgraettinger): Reduce copies, possibly via SpdyPinnableBufferPiece.
88 // The entry's index in the total set of entries ever inserted into the header
90 size_t insertion_index_;
98 #endif // NET_SPDY_HPACK_ENTRY_H_