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