| 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> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 } // namespace test | 27 } // namespace test |
| 28 | 28 |
| 29 typedef std::pair<size_t, uint32_t> InitialPeekResult; | 29 typedef std::pair<size_t, uint32_t> InitialPeekResult; |
| 30 | 30 |
| 31 // An HpackInputStream handles all the low-level details of decoding | 31 // An HpackInputStream handles all the low-level details of decoding |
| 32 // header fields. | 32 // header fields. |
| 33 class NET_EXPORT_PRIVATE HpackInputStream { | 33 class NET_EXPORT_PRIVATE HpackInputStream { |
| 34 public: | 34 public: |
| 35 friend class test::HpackInputStreamPeer; | 35 friend class test::HpackInputStreamPeer; |
| 36 | 36 |
| 37 // |max_string_literal_size| is the largest that any one string | 37 explicit HpackInputStream(base::StringPiece buffer); |
| 38 // literal (header name or header value) can be. | |
| 39 HpackInputStream(uint32_t max_string_literal_size, base::StringPiece buffer); | |
| 40 ~HpackInputStream(); | 38 ~HpackInputStream(); |
| 41 | 39 |
| 42 // Returns whether or not there is more data to process. | 40 // Returns whether or not there is more data to process. |
| 43 bool HasMoreData() const; | 41 bool HasMoreData() const; |
| 44 | 42 |
| 45 // If the next bits of input match |prefix|, consumes them and returns true. | 43 // If the next bits of input match |prefix|, consumes them and returns true. |
| 46 // Otherwise, consumes nothing and returns false. | 44 // Otherwise, consumes nothing and returns false. |
| 47 bool MatchPrefixAndConsume(HpackPrefix prefix); | 45 bool MatchPrefixAndConsume(HpackPrefix prefix); |
| 48 | 46 |
| 49 // The Decode* functions return true and fill in their arguments if | 47 // The Decode* functions return true and fill in their arguments if |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // position in the buffer after we successfully decode one opcode. | 83 // position in the buffer after we successfully decode one opcode. |
| 86 void MarkCurrentPosition(); | 84 void MarkCurrentPosition(); |
| 87 | 85 |
| 88 // Returning true indicates this instance of HpackInputStream | 86 // Returning true indicates this instance of HpackInputStream |
| 89 // doesn't have enough data to parse the current opcode, and we | 87 // doesn't have enough data to parse the current opcode, and we |
| 90 // are done with this instance. When more data arrive, a new | 88 // are done with this instance. When more data arrive, a new |
| 91 // HpackInputStream should be created to restart the parsing. | 89 // HpackInputStream should be created to restart the parsing. |
| 92 bool NeedMoreData() const; | 90 bool NeedMoreData() const; |
| 93 | 91 |
| 94 private: | 92 private: |
| 95 const uint32_t max_string_literal_size_; | |
| 96 base::StringPiece buffer_; | 93 base::StringPiece buffer_; |
| 97 size_t bit_offset_; | 94 size_t bit_offset_; |
| 98 // Total number of bytes parsed successfully. Only get updated when an | 95 // Total number of bytes parsed successfully. Only get updated when an |
| 99 // opcode is parsed successfully. | 96 // opcode is parsed successfully. |
| 100 uint32_t parsed_bytes_; | 97 uint32_t parsed_bytes_; |
| 101 // Total number of bytes parsed currently. Get updated when an octet, | 98 // Total number of bytes parsed currently. Get updated when an octet, |
| 102 // a number or a string has been parsed successfully. Can point to the | 99 // a number or a string has been parsed successfully. Can point to the |
| 103 // middle of an opcode. | 100 // middle of an opcode. |
| 104 uint32_t parsed_bytes_current_; | 101 uint32_t parsed_bytes_current_; |
| 105 bool need_more_data_; | 102 bool need_more_data_; |
| 106 | 103 |
| 107 bool PeekNextOctet(uint8_t* next_octet); | 104 bool PeekNextOctet(uint8_t* next_octet); |
| 108 | 105 |
| 109 bool DecodeNextOctet(uint8_t* next_octet); | 106 bool DecodeNextOctet(uint8_t* next_octet); |
| 110 | 107 |
| 111 DISALLOW_COPY_AND_ASSIGN(HpackInputStream); | 108 DISALLOW_COPY_AND_ASSIGN(HpackInputStream); |
| 112 }; | 109 }; |
| 113 | 110 |
| 114 } // namespace net | 111 } // namespace net |
| 115 | 112 |
| 116 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_ | 113 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_ |
| OLD | NEW |