Cast: Skip receiver log messages with time delta that can't be encoded.
[chromium-blink-merge.git] / net / spdy / hpack_input_stream.h
blob1a38dc651cccf8f51c6b944f513d6b472a1bd95a
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>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/macros.h"
13 #include "base/strings/string_piece.h"
14 #include "net/base/net_export.h"
15 #include "net/spdy/hpack_constants.h"
16 #include "net/spdy/hpack_huffman_table.h"
18 // All section references below are to
19 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-05
21 namespace net {
23 // TODO(akalin): When we use a callback/delegate instead of a vector,
24 // use StringPiece instead of string.
25 typedef std::pair<std::string, std::string> HpackHeaderPair;
26 typedef std::vector<HpackHeaderPair> HpackHeaderPairVector;
28 // An HpackInputStream handles all the low-level details of decoding
29 // header fields.
30 class NET_EXPORT_PRIVATE HpackInputStream {
31 public:
32 // |max_string_literal_size| is the largest that any one string
33 // literal (header name or header value) can be.
34 HpackInputStream(uint32 max_string_literal_size, base::StringPiece buffer);
35 ~HpackInputStream();
37 // Returns whether or not there is more data to process.
38 bool HasMoreData() const;
40 // If the next octet has the top |size| bits equal to |bits|,
41 // consumes it and returns true. Otherwise, consumes nothing and
42 // returns false.
43 bool MatchPrefixAndConsume(HpackPrefix prefix);
45 // The Decode* functions return true and fill in their arguments if
46 // decoding was successful, or false if an error was encountered.
48 bool DecodeNextUint32(uint32* I);
49 bool DecodeNextIdentityString(base::StringPiece* str);
50 bool DecodeNextHuffmanString(const HpackHuffmanTable& table,
51 std::string* str);
53 // Stores input bits into the most-significant, unfilled bits of |out|.
54 // |peeked_count| is the number of filled bits in |out| which have been
55 // previously peeked. PeekBits() will fill some number of remaining bits,
56 // returning the new total number via |peeked_count|. Returns true if one
57 // or more additional bits could be peeked, and false otherwise.
58 bool PeekBits(size_t* peeked_count, uint32* out);
60 // Consumes |count| bits of input. Generally paired with PeekBits().
61 void ConsumeBits(size_t count);
63 // If not currently on a byte boundary, consumes and discards
64 // remaining bits in the current byte.
65 void ConsumeByteRemainder();
67 // Accessors for testing.
69 void SetBitOffsetForTest(size_t bit_offset) {
70 bit_offset_ = bit_offset;
73 bool DecodeNextUint32ForTest(uint32* I) {
74 return DecodeNextUint32(I);
77 private:
78 const uint32 max_string_literal_size_;
79 base::StringPiece buffer_;
80 size_t bit_offset_;
82 bool PeekNextOctet(uint8* next_octet);
84 bool DecodeNextOctet(uint8* next_octet);
86 DISALLOW_COPY_AND_ASSIGN(HpackInputStream);
89 } // namespace net
91 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_