OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_SPDY_HPACK_OUTPUT_STREAM_H_ | 5 #ifndef NET_SPDY_HPACK_OUTPUT_STREAM_H_ |
6 #define NET_SPDY_HPACK_OUTPUT_STREAM_H_ | 6 #define NET_SPDY_HPACK_OUTPUT_STREAM_H_ |
7 | 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
8 #include <map> | 11 #include <map> |
9 #include <string> | 12 #include <string> |
10 | 13 |
11 #include "base/basictypes.h" | |
12 #include "base/macros.h" | 14 #include "base/macros.h" |
13 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
14 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
15 #include "net/spdy/hpack/hpack_constants.h" | 17 #include "net/spdy/hpack/hpack_constants.h" |
16 | 18 |
17 // All section references below are to | 19 // All section references below are to |
18 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 | 20 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 |
19 | 21 |
20 namespace net { | 22 namespace net { |
21 | 23 |
22 // An HpackOutputStream handles all the low-level details of encoding | 24 // An HpackOutputStream handles all the low-level details of encoding |
23 // header fields. | 25 // header fields. |
24 class NET_EXPORT_PRIVATE HpackOutputStream { | 26 class NET_EXPORT_PRIVATE HpackOutputStream { |
25 public: | 27 public: |
26 explicit HpackOutputStream(); | 28 explicit HpackOutputStream(); |
27 ~HpackOutputStream(); | 29 ~HpackOutputStream(); |
28 | 30 |
29 // Appends the lower |bit_size| bits of |bits| to the internal buffer. | 31 // Appends the lower |bit_size| bits of |bits| to the internal buffer. |
30 // | 32 // |
31 // |bit_size| must be > 0 and <= 8. |bits| must not have any bits | 33 // |bit_size| must be > 0 and <= 8. |bits| must not have any bits |
32 // set other than the lower |bit_size| bits. | 34 // set other than the lower |bit_size| bits. |
33 void AppendBits(uint8 bits, size_t bit_size); | 35 void AppendBits(uint8_t bits, size_t bit_size); |
34 | 36 |
35 // Simply forwards to AppendBits(prefix.bits, prefix.bit-size). | 37 // Simply forwards to AppendBits(prefix.bits, prefix.bit-size). |
36 void AppendPrefix(HpackPrefix prefix); | 38 void AppendPrefix(HpackPrefix prefix); |
37 | 39 |
38 // Directly appends |buffer|. | 40 // Directly appends |buffer|. |
39 void AppendBytes(base::StringPiece buffer); | 41 void AppendBytes(base::StringPiece buffer); |
40 | 42 |
41 // Appends the given integer using the representation described in | 43 // Appends the given integer using the representation described in |
42 // 6.1. If the internal buffer ends on a byte boundary, the prefix | 44 // 6.1. If the internal buffer ends on a byte boundary, the prefix |
43 // length N is taken to be 8; otherwise, it is taken to be the | 45 // length N is taken to be 8; otherwise, it is taken to be the |
44 // number of bits to the next byte boundary. | 46 // number of bits to the next byte boundary. |
45 // | 47 // |
46 // It is guaranteed that the internal buffer will end on a byte | 48 // It is guaranteed that the internal buffer will end on a byte |
47 // boundary after this function is called. | 49 // boundary after this function is called. |
48 void AppendUint32(uint32 I); | 50 void AppendUint32(uint32_t I); |
49 | 51 |
50 // Swaps the interal buffer with |output|. | 52 // Swaps the interal buffer with |output|. |
51 void TakeString(std::string* output); | 53 void TakeString(std::string* output); |
52 | 54 |
53 private: | 55 private: |
54 // The internal bit buffer. | 56 // The internal bit buffer. |
55 std::string buffer_; | 57 std::string buffer_; |
56 | 58 |
57 // If 0, the buffer ends on a byte boundary. If non-zero, the buffer | 59 // If 0, the buffer ends on a byte boundary. If non-zero, the buffer |
58 // ends on the most significant nth bit. Guaranteed to be < 8. | 60 // ends on the most significant nth bit. Guaranteed to be < 8. |
59 size_t bit_offset_; | 61 size_t bit_offset_; |
60 | 62 |
61 DISALLOW_COPY_AND_ASSIGN(HpackOutputStream); | 63 DISALLOW_COPY_AND_ASSIGN(HpackOutputStream); |
62 }; | 64 }; |
63 | 65 |
64 } // namespace net | 66 } // namespace net |
65 | 67 |
66 #endif // NET_SPDY_HPACK_OUTPUT_STREAM_H_ | 68 #endif // NET_SPDY_HPACK_OUTPUT_STREAM_H_ |
OLD | NEW |