rAc - revert invalid suggestions to edit mode
[chromium-blink-merge.git] / net / spdy / hpack_input_stream.h
blob17a057acdb6af15eb58ed77ad4e5a115f543579d
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" // For HpackPrefix.
17 // All section references below are to
18 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-05
19 // .
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 DecodeNextStringLiteral(base::StringPiece* str);
51 // Accessors for testing.
53 void SetBitOffsetForTest(size_t bit_offset) {
54 bit_offset_ = bit_offset;
57 bool DecodeNextUint32ForTest(uint32* I) {
58 return DecodeNextUint32(I);
61 bool DecodeNextStringLiteralForTest(base::StringPiece *str) {
62 return DecodeNextStringLiteral(str);
65 private:
66 const uint32 max_string_literal_size_;
67 base::StringPiece buffer_;
68 size_t bit_offset_;
70 bool PeekNextOctet(uint8* next_octet);
72 bool DecodeNextOctet(uint8* next_octet);
74 DISALLOW_COPY_AND_ASSIGN(HpackInputStream);
77 } // namespace net
79 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_