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_
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
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
30 class NET_EXPORT_PRIVATE HpackInputStream
{
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
);
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
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
);
66 const uint32 max_string_literal_size_
;
67 base::StringPiece buffer_
;
70 bool PeekNextOctet(uint8
* next_octet
);
72 bool DecodeNextOctet(uint8
* next_octet
);
74 DISALLOW_COPY_AND_ASSIGN(HpackInputStream
);
79 #endif // NET_SPDY_HPACK_INPUT_STREAM_H_