| 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> | 8 #include <cstddef> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 15 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
| 16 | 16 |
| 17 // All section references below are to | 17 // All section references below are to |
| 18 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-07 | 18 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 | 21 |
| 22 // A structure for an entry in the header table (3.1.2) and the | 22 // A structure for an entry in the header table (3.2) and the |
| 23 // reference set (3.1.3). | 23 // reference set (3.3). |
| 24 class NET_EXPORT_PRIVATE HpackEntry { | 24 class NET_EXPORT_PRIVATE HpackEntry { |
| 25 public: | 25 public: |
| 26 // The constant amount added to name().size() and value().size() to | 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. | 27 // get the size of an HpackEntry as defined in 5.1. |
| 28 static const size_t kSizeOverhead; | 28 static const size_t kSizeOverhead; |
| 29 | 29 |
| 30 // Creates an entry. Preconditions: | 30 // Creates an entry. Preconditions: |
| 31 // - |is_static| captures whether this entry is a member of the static | 31 // - |is_static| captures whether this entry is a member of the static |
| 32 // or dynamic header table. | 32 // or dynamic header table. |
| 33 // - |insertion_index| is this entry's index in the total set of entries ever | 33 // - |insertion_index| is this entry's index in the total set of entries ever |
| 34 // inserted into the header table (including static entries). | 34 // inserted into the header table (including static entries). |
| 35 // | 35 // |
| 36 // The combination of |is_static| and |insertion_index| allows an | 36 // The combination of |is_static| and |insertion_index| allows an |
| 37 // HpackEntryTable to determine the index of an HpackEntry in O(1) time. | 37 // HpackEntryTable to determine the index of an HpackEntry in O(1) time. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 61 bool IsLookup() const { return type_ == LOOKUP; } | 61 bool IsLookup() const { return type_ == LOOKUP; } |
| 62 | 62 |
| 63 // Returns and sets the state of the entry, or zero if never set. | 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. | 64 // The semantics of |state| are specific to the encoder or decoder. |
| 65 uint8 state() const { return state_; } | 65 uint8 state() const { return state_; } |
| 66 void set_state(uint8 state) { state_ = state; } | 66 void set_state(uint8 state) { state_ = state; } |
| 67 | 67 |
| 68 // Used to compute the entry's index in the header table. | 68 // Used to compute the entry's index in the header table. |
| 69 size_t InsertionIndex() const { return insertion_index_; } | 69 size_t InsertionIndex() const { return insertion_index_; } |
| 70 | 70 |
| 71 // Returns the size of an entry as defined in 3.3.1. | 71 // Returns the size of an entry as defined in 5.1. |
| 72 static size_t Size(base::StringPiece name, base::StringPiece value); | 72 static size_t Size(base::StringPiece name, base::StringPiece value); |
| 73 size_t Size() const; | 73 size_t Size() const; |
| 74 | 74 |
| 75 std::string GetDebugString() const; | 75 std::string GetDebugString() const; |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 enum EntryType { | 78 enum EntryType { |
| 79 LOOKUP, | 79 LOOKUP, |
| 80 DYNAMIC, | 80 DYNAMIC, |
| 81 STATIC, | 81 STATIC, |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 // TODO(jgraettinger): Reduce copies, possibly via SpdyPinnableBufferPiece. | 84 // TODO(jgraettinger): Reduce copies, possibly via SpdyPinnableBufferPiece. |
| 85 std::string name_; | 85 std::string name_; |
| 86 std::string value_; | 86 std::string value_; |
| 87 | 87 |
| 88 // The entry's index in the total set of entries ever inserted into the header | 88 // The entry's index in the total set of entries ever inserted into the header |
| 89 // table. | 89 // table. |
| 90 size_t insertion_index_; | 90 size_t insertion_index_; |
| 91 | 91 |
| 92 uint8 state_; | 92 uint8 state_; |
| 93 EntryType type_; | 93 EntryType type_; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 } // namespace net | 96 } // namespace net |
| 97 | 97 |
| 98 #endif // NET_SPDY_HPACK_ENTRY_H_ | 98 #endif // NET_SPDY_HPACK_ENTRY_H_ |
| OLD | NEW |