| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_SPDY_HPACK_ENTRY_H_ | 5 #ifndef NET_SPDY_HPACK_ENTRY_H_ |
| 6 #define NET_SPDY_HPACK_ENTRY_H_ | 6 #define NET_SPDY_HPACK_ENTRY_H_ |
| 7 | 7 |
| 8 #include <cstddef> | |
| 9 #include <set> | |
| 10 #include <string> | 8 #include <string> |
| 11 | 9 |
| 12 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 13 #include "base/macros.h" | 11 #include "base/macros.h" |
| 14 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 15 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 16 | 14 |
| 17 // All section references below are to | 15 // All section references below are to |
| 18 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 | 16 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 |
| 19 | 17 |
| 20 namespace net { | 18 namespace net { |
| 21 | 19 |
| 22 // A structure for an entry in the static table (3.3.1) | 20 // A structure for an entry in the static table (3.3.1) |
| 23 // and the header table (3.3.2). | 21 // and the header table (3.3.2). |
| 24 class NET_EXPORT_PRIVATE HpackEntry { | 22 class NET_EXPORT_PRIVATE HpackEntry { |
| 25 public: | 23 public: |
| 26 // The constant amount added to name().size() and value().size() to | 24 // The constant amount added to name().size() and value().size() to |
| 27 // get the size of an HpackEntry as defined in 5.1. | 25 // get the size of an HpackEntry as defined in 5.1. |
| 28 static const size_t kSizeOverhead; | 26 static const size_t kSizeOverhead; |
| 29 | 27 |
| 30 // Creates an entry. Preconditions: | 28 // Creates an entry. Preconditions: |
| 31 // - |is_static| captures whether this entry is a member of the static | 29 // - |is_static| captures whether this entry is a member of the static |
| 32 // or dynamic header table. | 30 // or dynamic header table. |
| 33 // - |insertion_index| is this entry's index in the total set of entries ever | 31 // - |insertion_index| is this entry's index in the total set of entries ever |
| 34 // inserted into the header table (including static entries). | 32 // inserted into the header table (including static entries). |
| 35 // | 33 // |
| 36 // The combination of |is_static| and |insertion_index| allows an | 34 // The combination of |is_static| and |insertion_index| allows an |
| 37 // HpackEntryTable to determine the index of an HpackEntry in O(1) time. | 35 // HpackEntryTable to determine the index of an HpackEntry in O(1) time. |
| 36 // Copies |name| and |value|. |
| 38 HpackEntry(base::StringPiece name, | 37 HpackEntry(base::StringPiece name, |
| 39 base::StringPiece value, | 38 base::StringPiece value, |
| 40 bool is_static, | 39 bool is_static, |
| 41 size_t insertion_index); | 40 size_t insertion_index); |
| 42 | 41 |
| 43 // Create a 'lookup' entry (only) suitable for querying a HpackEntrySet. The | 42 // Create a 'lookup' entry (only) suitable for querying a HpackEntrySet. The |
| 44 // instance InsertionIndex() always returns 0 and IsLookup() returns true. | 43 // instance InsertionIndex() always returns 0 and IsLookup() returns true. |
| 44 // The memory backing |name| and |value| must outlive this object. |
| 45 HpackEntry(base::StringPiece name, base::StringPiece value); | 45 HpackEntry(base::StringPiece name, base::StringPiece value); |
| 46 | 46 |
| 47 HpackEntry(const HpackEntry& other); |
| 48 HpackEntry& operator=(const HpackEntry& other); |
| 49 |
| 47 // Creates an entry with empty name and value. Only defined so that | 50 // Creates an entry with empty name and value. Only defined so that |
| 48 // entries can be stored in STL containers. | 51 // entries can be stored in STL containers. |
| 49 HpackEntry(); | 52 HpackEntry(); |
| 50 | 53 |
| 51 ~HpackEntry(); | 54 ~HpackEntry(); |
| 52 | 55 |
| 53 const std::string& name() const { return name_; } | 56 base::StringPiece name() const { return name_ref_; } |
| 54 const std::string& value() const { return value_; } | 57 base::StringPiece value() const { return value_ref_; } |
| 55 | 58 |
| 56 // Returns whether this entry is a member of the static (as opposed to | 59 // Returns whether this entry is a member of the static (as opposed to |
| 57 // dynamic) table. | 60 // dynamic) table. |
| 58 bool IsStatic() const { return type_ == STATIC; } | 61 bool IsStatic() const { return type_ == STATIC; } |
| 59 | 62 |
| 60 // Returns whether this entry is a lookup-only entry. | 63 // Returns whether this entry is a lookup-only entry. |
| 61 bool IsLookup() const { return type_ == LOOKUP; } | 64 bool IsLookup() const { return type_ == LOOKUP; } |
| 62 | 65 |
| 63 // Used to compute the entry's index in the header table. | 66 // Used to compute the entry's index in the header table. |
| 64 size_t InsertionIndex() const { return insertion_index_; } | 67 size_t InsertionIndex() const { return insertion_index_; } |
| 65 | 68 |
| 66 // Returns the size of an entry as defined in 5.1. | 69 // Returns the size of an entry as defined in 5.1. |
| 67 static size_t Size(base::StringPiece name, base::StringPiece value); | 70 static size_t Size(base::StringPiece name, base::StringPiece value); |
| 68 size_t Size() const; | 71 size_t Size() const; |
| 69 | 72 |
| 70 std::string GetDebugString() const; | 73 std::string GetDebugString() const; |
| 71 | 74 |
| 72 private: | 75 private: |
| 73 enum EntryType { | 76 enum EntryType { |
| 74 LOOKUP, | 77 LOOKUP, |
| 75 DYNAMIC, | 78 DYNAMIC, |
| 76 STATIC, | 79 STATIC, |
| 77 }; | 80 }; |
| 78 | 81 |
| 79 // TODO(jgraettinger): Reduce copies, possibly via SpdyPinnableBufferPiece. | 82 // These members are not used for LOOKUP entries. |
| 80 std::string name_; | 83 std::string name_; |
| 81 std::string value_; | 84 std::string value_; |
| 82 | 85 |
| 86 // These members are always valid. For DYNAMIC and STATIC entries, they |
| 87 // always point to |name_| and |value_|. |
| 88 base::StringPiece name_ref_; |
| 89 base::StringPiece value_ref_; |
| 90 |
| 83 // The entry's index in the total set of entries ever inserted into the header | 91 // The entry's index in the total set of entries ever inserted into the header |
| 84 // table. | 92 // table. |
| 85 size_t insertion_index_; | 93 size_t insertion_index_; |
| 86 | 94 |
| 87 EntryType type_; | 95 EntryType type_; |
| 88 }; | 96 }; |
| 89 | 97 |
| 90 } // namespace net | 98 } // namespace net |
| 91 | 99 |
| 92 #endif // NET_SPDY_HPACK_ENTRY_H_ | 100 #endif // NET_SPDY_HPACK_ENTRY_H_ |
| OLD | NEW |