Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Side by Side Diff: net/spdy/hpack_output_stream.h

Issue 246073007: SPDY & HPACK: Land recent internal changes (through 65328503) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on upstream change: Expanded FRAME_TOO_LARGE/FRAME_SIZE_ERROR comment. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/hpack_huffman_table_test.cc ('k') | net/spdy/hpack_output_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "net/base/net_export.h" 14 #include "net/base/net_export.h"
15 #include "net/spdy/hpack_constants.h" // For HpackPrefix. 15 #include "net/spdy/hpack_constants.h"
16 #include "net/spdy/hpack_encoding_context.h"
17 16
18 // All section references below are to 17 // All section references below are to
19 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-06 18 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-06
20 19
21 namespace net { 20 namespace net {
22 21
23 // An HpackOutputStream handles all the low-level details of encoding 22 // An HpackOutputStream handles all the low-level details of encoding
24 // header fields. 23 // header fields.
25 class NET_EXPORT_PRIVATE HpackOutputStream { 24 class NET_EXPORT_PRIVATE HpackOutputStream {
26 public: 25 public:
27 // |max_string_literal_size| is the largest that any one string 26 explicit HpackOutputStream();
28 // |literal (header name or header value) can be.
29 explicit HpackOutputStream(uint32 max_string_literal_size);
30 ~HpackOutputStream(); 27 ~HpackOutputStream();
31 28
32 // Corresponds to 4.2.
33 void AppendIndexedHeader(uint32 index_or_zero);
34
35 // Corresponds to 4.3.1 (second form). Returns whether or not the
36 // append was successful; if the append was unsuccessful, no other
37 // member function may be called.
38 bool AppendLiteralHeaderNoIndexingWithName(base::StringPiece name,
39 base::StringPiece value);
40
41 // Moves the internal buffer to the given string and clears all
42 // internal state.
43 void TakeString(std::string* output);
44
45 // Appends the lower |bit_size| bits of |bits| to the internal buffer. 29 // Appends the lower |bit_size| bits of |bits| to the internal buffer.
46 // 30 //
47 // |bit_size| must be > 0 and <= 8. |bits| must not have any bits 31 // |bit_size| must be > 0 and <= 8. |bits| must not have any bits
48 // set other than the lower |bit_size| bits. 32 // set other than the lower |bit_size| bits.
49 void AppendBits(uint8 bits, size_t bit_size); 33 void AppendBits(uint8 bits, size_t bit_size);
50 34
51 // Accessors for testing.
52
53 void AppendBitsForTest(uint8 bits, size_t size) {
54 AppendBits(bits, size);
55 }
56
57 void AppendUint32ForTest(uint32 I) {
58 AppendUint32(I);
59 }
60
61 bool AppendStringLiteralForTest(base::StringPiece str) {
62 return AppendStringLiteral(str);
63 }
64
65 private:
66 // Simply forwards to AppendBits(prefix.bits, prefix.bit-size). 35 // Simply forwards to AppendBits(prefix.bits, prefix.bit-size).
67 void AppendPrefix(HpackPrefix prefix); 36 void AppendPrefix(HpackPrefix prefix);
68 37
38 // Directly appends |buffer|.
39 void AppendBytes(base::StringPiece buffer);
40
69 // Appends the given integer using the representation described in 41 // Appends the given integer using the representation described in
70 // 4.1.1. If the internal buffer ends on a byte boundary, the prefix 42 // 4.1.1. If the internal buffer ends on a byte boundary, the prefix
71 // length N is taken to be 8; otherwise, it is taken to be the 43 // length N is taken to be 8; otherwise, it is taken to be the
72 // number of bits to the next byte boundary. 44 // number of bits to the next byte boundary.
73 // 45 //
74 // It is guaranteed that the internal buffer will end on a byte 46 // It is guaranteed that the internal buffer will end on a byte
75 // boundary after this function is called. 47 // boundary after this function is called.
76 void AppendUint32(uint32 I); 48 void AppendUint32(uint32 I);
77 49
78 // Appends the given string using the representation described in 50 // Swaps the interal buffer with |output|.
79 // 4.1.2. The internal buffer must end on a byte boundary, and it is 51 void TakeString(std::string* output);
80 // guaranteed that the internal buffer will end on a byte boundary
81 // after this function is called. Returns whether or not the append
82 // was successful; if the append was unsuccessful, no other member
83 // function may be called.
84 bool AppendStringLiteral(base::StringPiece str);
85 52
86 const uint32 max_string_literal_size_; 53 private:
87
88 // The internal bit buffer. 54 // The internal bit buffer.
89 std::string buffer_; 55 std::string buffer_;
90 56
91 // If 0, the buffer ends on a byte boundary. If non-zero, the buffer 57 // If 0, the buffer ends on a byte boundary. If non-zero, the buffer
92 // ends on the most significant nth bit. Guaranteed to be < 8. 58 // ends on the most significant nth bit. Guaranteed to be < 8.
93 size_t bit_offset_; 59 size_t bit_offset_;
94 60
95 DISALLOW_COPY_AND_ASSIGN(HpackOutputStream); 61 DISALLOW_COPY_AND_ASSIGN(HpackOutputStream);
96 }; 62 };
97 63
98 } // namespace net 64 } // namespace net
99 65
100 #endif // NET_SPDY_HPACK_OUTPUT_STREAM_H_ 66 #endif // NET_SPDY_HPACK_OUTPUT_STREAM_H_
OLDNEW
« no previous file with comments | « net/spdy/hpack_huffman_table_test.cc ('k') | net/spdy/hpack_output_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698