Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: net/spdy/hpack/hpack_input_stream.h

Issue 1568423002: Implement better HPACK Huffman code decoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not use binary literals. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/hpack/hpack_huffman_table_test.cc ('k') | net/spdy/hpack/hpack_input_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/strings/string_piece.h" 15 #include "base/strings/string_piece.h"
15 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
16 #include "net/spdy/hpack/hpack_constants.h" 17 #include "net/spdy/hpack/hpack_constants.h"
17 #include "net/spdy/hpack/hpack_huffman_table.h" 18 #include "net/spdy/hpack/hpack_huffman_table.h"
18 19
19 // All section references below are to 20 // All section references below are to
20 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 21 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08
21 22
22 namespace net { 23 namespace net {
23 24
25 typedef std::pair<size_t, uint32_t> InitialPeekResult;
26
24 // An HpackInputStream handles all the low-level details of decoding 27 // An HpackInputStream handles all the low-level details of decoding
25 // header fields. 28 // header fields.
26 class NET_EXPORT_PRIVATE HpackInputStream { 29 class NET_EXPORT_PRIVATE HpackInputStream {
27 public: 30 public:
28 // |max_string_literal_size| is the largest that any one string 31 // |max_string_literal_size| is the largest that any one string
29 // literal (header name or header value) can be. 32 // literal (header name or header value) can be.
30 HpackInputStream(uint32_t max_string_literal_size, base::StringPiece buffer); 33 HpackInputStream(uint32_t max_string_literal_size, base::StringPiece buffer);
31 ~HpackInputStream(); 34 ~HpackInputStream();
32 35
33 // Returns whether or not there is more data to process. 36 // Returns whether or not there is more data to process.
34 bool HasMoreData() const; 37 bool HasMoreData() const;
35 38
36 // If the next bits of input match |prefix|, consumes them and returns true. 39 // If the next bits of input match |prefix|, consumes them and returns true.
37 // Otherwise, consumes nothing and returns false. 40 // Otherwise, consumes nothing and returns false.
38 bool MatchPrefixAndConsume(HpackPrefix prefix); 41 bool MatchPrefixAndConsume(HpackPrefix prefix);
39 42
40 // The Decode* functions return true and fill in their arguments if 43 // The Decode* functions return true and fill in their arguments if
41 // decoding was successful, or false if an error was encountered. 44 // decoding was successful, or false if an error was encountered.
42 45
43 bool DecodeNextUint32(uint32_t* I); 46 bool DecodeNextUint32(uint32_t* I);
44 bool DecodeNextIdentityString(base::StringPiece* str); 47 bool DecodeNextIdentityString(base::StringPiece* str);
45 bool DecodeNextHuffmanString(const HpackHuffmanTable& table, 48 bool DecodeNextHuffmanString(std::string* str);
46 std::string* str);
47 49
48 // Stores input bits into the most-significant, unfilled bits of |out|. 50 // Stores input bits into the most-significant, unfilled bits of |out|.
49 // |peeked_count| is the number of filled bits in |out| which have been 51 // |peeked_count| is the number of filled bits in |out| which have been
50 // previously peeked. PeekBits() will fill some number of remaining bits, 52 // previously peeked. PeekBits() will fill some number of remaining bits,
51 // returning the new total number via |peeked_count|. Returns true if one 53 // returning the new total number via |peeked_count|. Returns true if one
52 // or more additional bits could be peeked, and false otherwise. 54 // or more additional bits were added to |out|, and false otherwise.
53 bool PeekBits(size_t* peeked_count, uint32_t* out) const; 55 bool PeekBits(size_t* peeked_count, uint32_t* out) const;
54 56
57 // Similar to PeekBits, but intended to be used when starting to decode a
58 // Huffman encoded string. Returns a pair containing the peeked_count and
59 // out values as described for PeekBits, with the bits from the first N bytes
60 // of buffer_, where N == min(4, buffer_.size()), starting with the high
61 // order bits.
62 // Should only be called when first peeking at bits from the input stream as
63 // it does not take peeked_count as an input, so doesn't know how many bits
64 // have already been returned by previous calls to InitializePeekBits and
65 // PeekBits.
66 InitialPeekResult InitializePeekBits();
67
55 // Consumes |count| bits of input. Generally paired with PeekBits(). 68 // Consumes |count| bits of input. Generally paired with PeekBits().
56 void ConsumeBits(size_t count); 69 void ConsumeBits(size_t count);
57 70
58 // If not currently on a byte boundary, consumes and discards 71 // If not currently on a byte boundary, consumes and discards
59 // remaining bits in the current byte. 72 // remaining bits in the current byte.
60 void ConsumeByteRemainder(); 73 void ConsumeByteRemainder();
61 74
62 // Accessors for testing. 75 // Accessors for testing.
63 76
64 void SetBitOffsetForTest(size_t bit_offset) { bit_offset_ = bit_offset; } 77 void SetBitOffsetForTest(size_t bit_offset) { bit_offset_ = bit_offset; }
65 78
66 private: 79 private:
67 const uint32_t max_string_literal_size_; 80 const uint32_t max_string_literal_size_;
68 base::StringPiece buffer_; 81 base::StringPiece buffer_;
69 size_t bit_offset_; 82 size_t bit_offset_;
70 83
71 bool PeekNextOctet(uint8_t* next_octet); 84 bool PeekNextOctet(uint8_t* next_octet);
72 85
73 bool DecodeNextOctet(uint8_t* next_octet); 86 bool DecodeNextOctet(uint8_t* next_octet);
74 87
75 DISALLOW_COPY_AND_ASSIGN(HpackInputStream); 88 DISALLOW_COPY_AND_ASSIGN(HpackInputStream);
76 }; 89 };
77 90
78 } // namespace net 91 } // namespace net
79 92
80 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_ 93 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_
OLDNEW
« no previous file with comments | « net/spdy/hpack/hpack_huffman_table_test.cc ('k') | net/spdy/hpack/hpack_input_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698