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_
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_constants.h"
15 #include "net/spdy/hpack_huffman_table.h"
17 // All section references below are to
18 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08
22 // An HpackInputStream handles all the low-level details of decoding
24 class NET_EXPORT_PRIVATE HpackInputStream
{
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
);
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
,
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
) {
63 bit_offset_
= bit_offset
;
67 const uint32 max_string_literal_size_
;
68 base::StringPiece buffer_
;
71 bool PeekNextOctet(uint8
* next_octet
);
73 bool DecodeNextOctet(uint8
* next_octet
);
75 DISALLOW_COPY_AND_ASSIGN(HpackInputStream
);
80 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_