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_HPACK_ENCODER_H_ | 5 #ifndef NET_SPDY_HPACK_HPACK_ENCODER_H_ |
6 #define NET_SPDY_HPACK_HPACK_ENCODER_H_ | 6 #define NET_SPDY_HPACK_HPACK_ENCODER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <functional> | 10 #include <functional> |
11 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | |
14 #include <utility> | 13 #include <utility> |
15 #include <vector> | 14 #include <vector> |
16 | 15 |
17 #include "base/macros.h" | 16 #include "base/macros.h" |
18 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
19 #include "net/spdy/hpack/hpack_header_table.h" | 18 #include "net/spdy/hpack/hpack_header_table.h" |
20 #include "net/spdy/hpack/hpack_output_stream.h" | 19 #include "net/spdy/hpack/hpack_output_stream.h" |
| 20 #include "net/spdy/platform/api/spdy_string.h" |
21 #include "net/spdy/platform/api/spdy_string_piece.h" | 21 #include "net/spdy/platform/api/spdy_string_piece.h" |
22 #include "net/spdy/spdy_protocol.h" | 22 #include "net/spdy/spdy_protocol.h" |
23 | 23 |
24 // An HpackEncoder encodes header sets as outlined in | 24 // An HpackEncoder encodes header sets as outlined in |
25 // http://tools.ietf.org/html/rfc7541. | 25 // http://tools.ietf.org/html/rfc7541. |
26 | 26 |
27 namespace net { | 27 namespace net { |
28 | 28 |
29 class HpackHuffmanTable; | 29 class HpackHuffmanTable; |
30 | 30 |
(...skipping 14 matching lines...) Expand all Loading... |
45 // pair should be inserted into the HPACK dynamic table. | 45 // pair should be inserted into the HPACK dynamic table. |
46 using IndexingPolicy = std::function<bool(SpdyStringPiece, SpdyStringPiece)>; | 46 using IndexingPolicy = std::function<bool(SpdyStringPiece, SpdyStringPiece)>; |
47 | 47 |
48 // |table| is an initialized HPACK Huffman table, having an | 48 // |table| is an initialized HPACK Huffman table, having an |
49 // externally-managed lifetime which spans beyond HpackEncoder. | 49 // externally-managed lifetime which spans beyond HpackEncoder. |
50 explicit HpackEncoder(const HpackHuffmanTable& table); | 50 explicit HpackEncoder(const HpackHuffmanTable& table); |
51 ~HpackEncoder(); | 51 ~HpackEncoder(); |
52 | 52 |
53 // Encodes a sequence of Representations into the given string. | 53 // Encodes a sequence of Representations into the given string. |
54 void EncodeHeaderSet(const Representations& representations, | 54 void EncodeHeaderSet(const Representations& representations, |
55 std::string* output); | 55 SpdyString* output); |
56 | 56 |
57 // Encodes the given header set into the given string. Returns | 57 // Encodes the given header set into the given string. Returns |
58 // whether or not the encoding was successful. | 58 // whether or not the encoding was successful. |
59 bool EncodeHeaderSet(const SpdyHeaderBlock& header_set, std::string* output); | 59 bool EncodeHeaderSet(const SpdyHeaderBlock& header_set, SpdyString* output); |
60 | 60 |
61 class NET_EXPORT_PRIVATE ProgressiveEncoder { | 61 class NET_EXPORT_PRIVATE ProgressiveEncoder { |
62 public: | 62 public: |
63 virtual ~ProgressiveEncoder() {} | 63 virtual ~ProgressiveEncoder() {} |
64 | 64 |
65 // Returns true iff more remains to encode. | 65 // Returns true iff more remains to encode. |
66 virtual bool HasNext() const = 0; | 66 virtual bool HasNext() const = 0; |
67 | 67 |
68 // Encodes up to max_encoded_bytes of the current header block into the | 68 // Encodes up to max_encoded_bytes of the current header block into the |
69 // given output string. | 69 // given output string. |
70 virtual void Next(size_t max_encoded_bytes, std::string* output) = 0; | 70 virtual void Next(size_t max_encoded_bytes, SpdyString* output) = 0; |
71 }; | 71 }; |
72 | 72 |
73 // Returns a ProgressiveEncoder which must be outlived by both the given | 73 // Returns a ProgressiveEncoder which must be outlived by both the given |
74 // SpdyHeaderBlock and this object. | 74 // SpdyHeaderBlock and this object. |
75 std::unique_ptr<ProgressiveEncoder> EncodeHeaderSet( | 75 std::unique_ptr<ProgressiveEncoder> EncodeHeaderSet( |
76 const SpdyHeaderBlock& header_set); | 76 const SpdyHeaderBlock& header_set); |
77 | 77 |
78 // Called upon a change to SETTINGS_HEADER_TABLE_SIZE. Specifically, this | 78 // Called upon a change to SETTINGS_HEADER_TABLE_SIZE. Specifically, this |
79 // is to be called after receiving (and sending an acknowledgement for) a | 79 // is to be called after receiving (and sending an acknowledgement for) a |
80 // SETTINGS_HEADER_TABLE_SIZE update from the remote decoding endpoint. | 80 // SETTINGS_HEADER_TABLE_SIZE update from the remote decoding endpoint. |
(...skipping 21 matching lines...) Expand all Loading... |
102 // Returns the estimate of dynamically allocated memory in bytes. | 102 // Returns the estimate of dynamically allocated memory in bytes. |
103 size_t EstimateMemoryUsage() const; | 103 size_t EstimateMemoryUsage() const; |
104 | 104 |
105 private: | 105 private: |
106 friend class test::HpackEncoderPeer; | 106 friend class test::HpackEncoderPeer; |
107 | 107 |
108 class RepresentationIterator; | 108 class RepresentationIterator; |
109 class Encoderator; | 109 class Encoderator; |
110 | 110 |
111 // Encodes a sequence of header name-value pairs as a single header block. | 111 // Encodes a sequence of header name-value pairs as a single header block. |
112 void EncodeRepresentations(RepresentationIterator* iter, std::string* output); | 112 void EncodeRepresentations(RepresentationIterator* iter, SpdyString* output); |
113 | 113 |
114 // Emits a static/dynamic indexed representation (Section 7.1). | 114 // Emits a static/dynamic indexed representation (Section 7.1). |
115 void EmitIndex(const HpackEntry* entry); | 115 void EmitIndex(const HpackEntry* entry); |
116 | 116 |
117 // Emits a literal representation (Section 7.2). | 117 // Emits a literal representation (Section 7.2). |
118 void EmitIndexedLiteral(const Representation& representation); | 118 void EmitIndexedLiteral(const Representation& representation); |
119 void EmitNonIndexedLiteral(const Representation& representation); | 119 void EmitNonIndexedLiteral(const Representation& representation); |
120 void EmitLiteral(const Representation& representation); | 120 void EmitLiteral(const Representation& representation); |
121 | 121 |
122 // Emits a Huffman or identity string (whichever is smaller). | 122 // Emits a Huffman or identity string (whichever is smaller). |
(...skipping 24 matching lines...) Expand all Loading... |
147 IndexingPolicy should_index_; | 147 IndexingPolicy should_index_; |
148 bool enable_compression_; | 148 bool enable_compression_; |
149 bool should_emit_table_size_; | 149 bool should_emit_table_size_; |
150 | 150 |
151 DISALLOW_COPY_AND_ASSIGN(HpackEncoder); | 151 DISALLOW_COPY_AND_ASSIGN(HpackEncoder); |
152 }; | 152 }; |
153 | 153 |
154 } // namespace net | 154 } // namespace net |
155 | 155 |
156 #endif // NET_SPDY_HPACK_HPACK_ENCODER_H_ | 156 #endif // NET_SPDY_HPACK_HPACK_ENCODER_H_ |
OLD | NEW |