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_INPUT_STREAM_H_ | 5 #ifndef NET_SPDY_HPACK_INPUT_STREAM_H_ |
6 #define NET_SPDY_HPACK_INPUT_STREAM_H_ | 6 #define NET_SPDY_HPACK_INPUT_STREAM_H_ |
7 | 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
8 #include <string> | 11 #include <string> |
9 | 12 |
10 #include "base/basictypes.h" | |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
13 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
14 #include "net/spdy/hpack/hpack_constants.h" | 16 #include "net/spdy/hpack/hpack_constants.h" |
15 #include "net/spdy/hpack/hpack_huffman_table.h" | 17 #include "net/spdy/hpack/hpack_huffman_table.h" |
16 | 18 |
17 // All section references below are to | 19 // All section references below are to |
18 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 | 20 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 |
19 | 21 |
20 namespace net { | 22 namespace net { |
21 | 23 |
22 // An HpackInputStream handles all the low-level details of decoding | 24 // An HpackInputStream handles all the low-level details of decoding |
23 // header fields. | 25 // header fields. |
24 class NET_EXPORT_PRIVATE HpackInputStream { | 26 class NET_EXPORT_PRIVATE HpackInputStream { |
25 public: | 27 public: |
26 // |max_string_literal_size| is the largest that any one string | 28 // |max_string_literal_size| is the largest that any one string |
27 // literal (header name or header value) can be. | 29 // literal (header name or header value) can be. |
28 HpackInputStream(uint32 max_string_literal_size, base::StringPiece buffer); | 30 HpackInputStream(uint32_t max_string_literal_size, base::StringPiece buffer); |
29 ~HpackInputStream(); | 31 ~HpackInputStream(); |
30 | 32 |
31 // Returns whether or not there is more data to process. | 33 // Returns whether or not there is more data to process. |
32 bool HasMoreData() const; | 34 bool HasMoreData() const; |
33 | 35 |
34 // If the next bits of input match |prefix|, consumes them and returns true. | 36 // If the next bits of input match |prefix|, consumes them and returns true. |
35 // Otherwise, consumes nothing and returns false. | 37 // Otherwise, consumes nothing and returns false. |
36 bool MatchPrefixAndConsume(HpackPrefix prefix); | 38 bool MatchPrefixAndConsume(HpackPrefix prefix); |
37 | 39 |
38 // The Decode* functions return true and fill in their arguments if | 40 // The Decode* functions return true and fill in their arguments if |
39 // decoding was successful, or false if an error was encountered. | 41 // decoding was successful, or false if an error was encountered. |
40 | 42 |
41 bool DecodeNextUint32(uint32* I); | 43 bool DecodeNextUint32(uint32_t* I); |
42 bool DecodeNextIdentityString(base::StringPiece* str); | 44 bool DecodeNextIdentityString(base::StringPiece* str); |
43 bool DecodeNextHuffmanString(const HpackHuffmanTable& table, | 45 bool DecodeNextHuffmanString(const HpackHuffmanTable& table, |
44 std::string* str); | 46 std::string* str); |
45 | 47 |
46 // Stores input bits into the most-significant, unfilled bits of |out|. | 48 // Stores input bits into the most-significant, unfilled bits of |out|. |
47 // |peeked_count| is the number of filled bits in |out| which have been | 49 // |peeked_count| is the number of filled bits in |out| which have been |
48 // previously peeked. PeekBits() will fill some number of remaining bits, | 50 // previously peeked. PeekBits() will fill some number of remaining bits, |
49 // returning the new total number via |peeked_count|. Returns true if one | 51 // returning the new total number via |peeked_count|. Returns true if one |
50 // or more additional bits could be peeked, and false otherwise. | 52 // or more additional bits could be peeked, and false otherwise. |
51 bool PeekBits(size_t* peeked_count, uint32* out) const; | 53 bool PeekBits(size_t* peeked_count, uint32_t* out) const; |
52 | 54 |
53 // Consumes |count| bits of input. Generally paired with PeekBits(). | 55 // Consumes |count| bits of input. Generally paired with PeekBits(). |
54 void ConsumeBits(size_t count); | 56 void ConsumeBits(size_t count); |
55 | 57 |
56 // If not currently on a byte boundary, consumes and discards | 58 // If not currently on a byte boundary, consumes and discards |
57 // remaining bits in the current byte. | 59 // remaining bits in the current byte. |
58 void ConsumeByteRemainder(); | 60 void ConsumeByteRemainder(); |
59 | 61 |
60 // Accessors for testing. | 62 // Accessors for testing. |
61 | 63 |
62 void SetBitOffsetForTest(size_t bit_offset) { bit_offset_ = bit_offset; } | 64 void SetBitOffsetForTest(size_t bit_offset) { bit_offset_ = bit_offset; } |
63 | 65 |
64 private: | 66 private: |
65 const uint32 max_string_literal_size_; | 67 const uint32_t max_string_literal_size_; |
66 base::StringPiece buffer_; | 68 base::StringPiece buffer_; |
67 size_t bit_offset_; | 69 size_t bit_offset_; |
68 | 70 |
69 bool PeekNextOctet(uint8* next_octet); | 71 bool PeekNextOctet(uint8_t* next_octet); |
70 | 72 |
71 bool DecodeNextOctet(uint8* next_octet); | 73 bool DecodeNextOctet(uint8_t* next_octet); |
72 | 74 |
73 DISALLOW_COPY_AND_ASSIGN(HpackInputStream); | 75 DISALLOW_COPY_AND_ASSIGN(HpackInputStream); |
74 }; | 76 }; |
75 | 77 |
76 } // namespace net | 78 } // namespace net |
77 | 79 |
78 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_ | 80 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_ |
OLD | NEW |