| 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 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 16 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
| 17 #include "net/spdy/hpack/hpack_constants.h" | 17 #include "net/spdy/hpack/hpack_constants.h" |
| 18 #include "net/spdy/hpack/hpack_huffman_table.h" | 18 #include "net/spdy/hpack/hpack_huffman_table.h" |
| 19 | 19 |
| 20 // All section references below are to | 20 // All section references below are to |
| 21 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 | 21 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 | 24 |
| 25 namespace test { |
| 26 class HpackInputStreamPeer; |
| 27 } // namespace test |
| 28 |
| 25 typedef std::pair<size_t, uint32_t> InitialPeekResult; | 29 typedef std::pair<size_t, uint32_t> InitialPeekResult; |
| 26 | 30 |
| 27 // An HpackInputStream handles all the low-level details of decoding | 31 // An HpackInputStream handles all the low-level details of decoding |
| 28 // header fields. | 32 // header fields. |
| 29 class NET_EXPORT_PRIVATE HpackInputStream { | 33 class NET_EXPORT_PRIVATE HpackInputStream { |
| 30 public: | 34 public: |
| 35 friend class test::HpackInputStreamPeer; |
| 36 |
| 31 // |max_string_literal_size| is the largest that any one string | 37 // |max_string_literal_size| is the largest that any one string |
| 32 // literal (header name or header value) can be. | 38 // literal (header name or header value) can be. |
| 33 HpackInputStream(uint32_t max_string_literal_size, base::StringPiece buffer); | 39 HpackInputStream(uint32_t max_string_literal_size, base::StringPiece buffer); |
| 34 ~HpackInputStream(); | 40 ~HpackInputStream(); |
| 35 | 41 |
| 36 // Returns whether or not there is more data to process. | 42 // Returns whether or not there is more data to process. |
| 37 bool HasMoreData() const; | 43 bool HasMoreData() const; |
| 38 | 44 |
| 39 // If the next bits of input match |prefix|, consumes them and returns true. | 45 // If the next bits of input match |prefix|, consumes them and returns true. |
| 40 // Otherwise, consumes nothing and returns false. | 46 // Otherwise, consumes nothing and returns false. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 65 // PeekBits. | 71 // PeekBits. |
| 66 InitialPeekResult InitializePeekBits(); | 72 InitialPeekResult InitializePeekBits(); |
| 67 | 73 |
| 68 // Consumes |count| bits of input. Generally paired with PeekBits(). | 74 // Consumes |count| bits of input. Generally paired with PeekBits(). |
| 69 void ConsumeBits(size_t count); | 75 void ConsumeBits(size_t count); |
| 70 | 76 |
| 71 // If not currently on a byte boundary, consumes and discards | 77 // If not currently on a byte boundary, consumes and discards |
| 72 // remaining bits in the current byte. | 78 // remaining bits in the current byte. |
| 73 void ConsumeByteRemainder(); | 79 void ConsumeByteRemainder(); |
| 74 | 80 |
| 75 // Accessors for testing. | 81 // Return the total bytes that have been parsed SUCCESSFULLY. |
| 82 uint32_t ParsedBytes() const; |
| 76 | 83 |
| 77 void SetBitOffsetForTest(size_t bit_offset) { bit_offset_ = bit_offset; } | 84 // When incrementally decode the header, need to remember the current |
| 85 // position in the buffer after we successfully decode one opcode. |
| 86 void MarkCurrentPosition(); |
| 87 |
| 88 // Returning true indicates this instance of HpackInputStream |
| 89 // doesn't have enough data to parse the current opcode, and we |
| 90 // are done with this instance. When more data arrive, a new |
| 91 // HpackInputStream should be created to restart the parsing. |
| 92 bool NeedMoreData() const; |
| 78 | 93 |
| 79 private: | 94 private: |
| 80 const uint32_t max_string_literal_size_; | 95 const uint32_t max_string_literal_size_; |
| 81 base::StringPiece buffer_; | 96 base::StringPiece buffer_; |
| 82 size_t bit_offset_; | 97 size_t bit_offset_; |
| 98 // Total number of bytes parsed successfully. Only get updated when an |
| 99 // opcode is parsed successfully. |
| 100 uint32_t parsed_bytes_; |
| 101 // 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 |
| 103 // middle of an opcode. |
| 104 uint32_t parsed_bytes_current_; |
| 105 bool need_more_data_; |
| 83 | 106 |
| 84 bool PeekNextOctet(uint8_t* next_octet); | 107 bool PeekNextOctet(uint8_t* next_octet); |
| 85 | 108 |
| 86 bool DecodeNextOctet(uint8_t* next_octet); | 109 bool DecodeNextOctet(uint8_t* next_octet); |
| 87 | 110 |
| 88 DISALLOW_COPY_AND_ASSIGN(HpackInputStream); | 111 DISALLOW_COPY_AND_ASSIGN(HpackInputStream); |
| 89 }; | 112 }; |
| 90 | 113 |
| 91 } // namespace net | 114 } // namespace net |
| 92 | 115 |
| 93 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_ | 116 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_ |
| OLD | NEW |