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_CORE_HPACK_HPACK_ENCODER_H_ | 5 #ifndef NET_SPDY_CORE_HPACK_HPACK_ENCODER_H_ |
6 #define NET_SPDY_CORE_HPACK_HPACK_ENCODER_H_ | 6 #define NET_SPDY_CORE_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 <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "net/base/net_export.h" | |
18 #include "net/spdy/core/hpack/hpack_header_table.h" | 17 #include "net/spdy/core/hpack/hpack_header_table.h" |
19 #include "net/spdy/core/hpack/hpack_output_stream.h" | 18 #include "net/spdy/core/hpack/hpack_output_stream.h" |
20 #include "net/spdy/core/spdy_protocol.h" | 19 #include "net/spdy/core/spdy_protocol.h" |
| 20 #include "net/spdy/platform/api/spdy_export.h" |
21 #include "net/spdy/platform/api/spdy_string.h" | 21 #include "net/spdy/platform/api/spdy_string.h" |
22 #include "net/spdy/platform/api/spdy_string_piece.h" | 22 #include "net/spdy/platform/api/spdy_string_piece.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 |
31 namespace test { | 31 namespace test { |
32 class HpackEncoderPeer; | 32 class HpackEncoderPeer; |
33 } // namespace test | 33 } // namespace test |
34 | 34 |
35 class NET_EXPORT_PRIVATE HpackEncoder { | 35 class SPDY_EXPORT_PRIVATE HpackEncoder { |
36 public: | 36 public: |
37 using Representation = std::pair<SpdyStringPiece, SpdyStringPiece>; | 37 using Representation = std::pair<SpdyStringPiece, SpdyStringPiece>; |
38 using Representations = std::vector<Representation>; | 38 using Representations = std::vector<Representation>; |
39 | 39 |
40 // Callers may provide a HeaderListener to be informed of header name-value | 40 // Callers may provide a HeaderListener to be informed of header name-value |
41 // pairs processed by this encoder. | 41 // pairs processed by this encoder. |
42 typedef std::function<void(SpdyStringPiece, SpdyStringPiece)> HeaderListener; | 42 typedef std::function<void(SpdyStringPiece, SpdyStringPiece)> HeaderListener; |
43 | 43 |
44 // An indexing policy should return true if the provided header name-value | 44 // An indexing policy should return true if the provided header name-value |
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 SpdyString* 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, SpdyString* output); | 59 bool EncodeHeaderSet(const SpdyHeaderBlock& header_set, SpdyString* output); |
60 | 60 |
61 class NET_EXPORT_PRIVATE ProgressiveEncoder { | 61 class SPDY_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, SpdyString* output) = 0; | 70 virtual void Next(size_t max_encoded_bytes, SpdyString* output) = 0; |
71 }; | 71 }; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after 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_CORE_HPACK_HPACK_ENCODER_H_ | 156 #endif // NET_SPDY_CORE_HPACK_HPACK_ENCODER_H_ |
OLD | NEW |