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_HPACK_OUTPUT_STREAM_H_ | 5 #ifndef NET_SPDY_HPACK_HPACK_OUTPUT_STREAM_H_ |
6 #define NET_SPDY_HPACK_HPACK_OUTPUT_STREAM_H_ | 6 #define NET_SPDY_HPACK_HPACK_OUTPUT_STREAM_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <string> | |
13 | 12 |
14 #include "base/macros.h" | 13 #include "base/macros.h" |
15 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
16 #include "net/spdy/hpack/hpack_constants.h" | 15 #include "net/spdy/hpack/hpack_constants.h" |
| 16 #include "net/spdy/platform/api/spdy_string.h" |
17 #include "net/spdy/platform/api/spdy_string_piece.h" | 17 #include "net/spdy/platform/api/spdy_string_piece.h" |
18 | 18 |
19 // All section references below are to | 19 // All section references below are to |
20 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 | 20 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 | 23 |
24 // An HpackOutputStream handles all the low-level details of encoding | 24 // An HpackOutputStream handles all the low-level details of encoding |
25 // header fields. | 25 // header fields. |
26 class NET_EXPORT_PRIVATE HpackOutputStream { | 26 class NET_EXPORT_PRIVATE HpackOutputStream { |
(...skipping 16 matching lines...) Expand all Loading... |
43 // Appends the given integer using the representation described in | 43 // Appends the given integer using the representation described in |
44 // 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 |
45 // 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 |
46 // number of bits to the next byte boundary. | 46 // number of bits to the next byte boundary. |
47 // | 47 // |
48 // 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 |
49 // boundary after this function is called. | 49 // boundary after this function is called. |
50 void AppendUint32(uint32_t I); | 50 void AppendUint32(uint32_t I); |
51 | 51 |
52 // Swaps the internal buffer with |output|, then resets state. | 52 // Swaps the internal buffer with |output|, then resets state. |
53 void TakeString(std::string* output); | 53 void TakeString(SpdyString* output); |
54 | 54 |
55 // Gives up to |max_size| bytes of the internal buffer to |output|. Resets | 55 // Gives up to |max_size| bytes of the internal buffer to |output|. Resets |
56 // internal state with the overflow. | 56 // internal state with the overflow. |
57 void BoundedTakeString(size_t max_size, std::string* output); | 57 void BoundedTakeString(size_t max_size, SpdyString* output); |
58 | 58 |
59 // Size in bytes of stream's internal buffer. | 59 // Size in bytes of stream's internal buffer. |
60 size_t size() const { return buffer_.size(); } | 60 size_t size() const { return buffer_.size(); } |
61 | 61 |
62 // Returns the estimate of dynamically allocated memory in bytes. | 62 // Returns the estimate of dynamically allocated memory in bytes. |
63 size_t EstimateMemoryUsage() const; | 63 size_t EstimateMemoryUsage() const; |
64 | 64 |
65 private: | 65 private: |
66 // The internal bit buffer. | 66 // The internal bit buffer. |
67 std::string buffer_; | 67 SpdyString buffer_; |
68 | 68 |
69 // If 0, the buffer ends on a byte boundary. If non-zero, the buffer | 69 // If 0, the buffer ends on a byte boundary. If non-zero, the buffer |
70 // ends on the nth most significant bit. Guaranteed to be < 8. | 70 // ends on the nth most significant bit. Guaranteed to be < 8. |
71 size_t bit_offset_; | 71 size_t bit_offset_; |
72 | 72 |
73 DISALLOW_COPY_AND_ASSIGN(HpackOutputStream); | 73 DISALLOW_COPY_AND_ASSIGN(HpackOutputStream); |
74 }; | 74 }; |
75 | 75 |
76 } // namespace net | 76 } // namespace net |
77 | 77 |
78 #endif // NET_SPDY_HPACK_HPACK_OUTPUT_STREAM_H_ | 78 #endif // NET_SPDY_HPACK_HPACK_OUTPUT_STREAM_H_ |
OLD | NEW |