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

Side by Side Diff: net/http2/tools/http2_frame_builder.h

Issue 2554683003: Revert of Add new HTTP/2 and HPACK decoder in net/http2/. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « net/http2/tools/http2_bug_tracker.h ('k') | net/http2/tools/http2_frame_builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #ifndef NET_HTTP2_TOOLS_HTTP2_FRAME_BUILDER_H_
6 #define NET_HTTP2_TOOLS_HTTP2_FRAME_BUILDER_H_
7
8 // Http2FrameBuilder builds wire-format HTTP/2 frames (or fragments thereof)
9 // from components.
10 //
11 // For now, this is only intended for use in tests, and thus has EXPECT* in the
12 // code. If desired to use it in an encoder, it will need optimization work,
13 // especially w.r.t memory mgmt, and the EXPECT* will need to be removed or
14 // replaced with DCHECKs.
15
16 #include <stddef.h> // for size_t
17
18 #include <string>
19
20 #include "base/strings/string_piece.h"
21 #include "net/http2/http2_constants.h"
22 #include "net/http2/http2_structures.h"
23
24 namespace net {
25 namespace test {
26
27 class Http2FrameBuilder {
28 public:
29 Http2FrameBuilder(Http2FrameType type, uint8_t flags, uint32_t stream_id);
30 explicit Http2FrameBuilder(const Http2FrameHeader& v);
31 Http2FrameBuilder() {}
32 ~Http2FrameBuilder() {}
33
34 size_t size() const { return buffer_.size(); }
35 const std::string& buffer() const { return buffer_; }
36
37 //----------------------------------------------------------------------------
38 // Methods for appending to the end of the buffer.
39
40 // Append a sequence of bytes from various sources.
41 void Append(base::StringPiece s);
42 void AppendBytes(const void* data, uint32_t num_bytes);
43
44 // Append an array of type T[N] to the string. Intended for tests with arrays
45 // initialized from literals, such as:
46 // const char kData[] = {0x12, 0x23, ...};
47 // builder.AppendBytes(kData);
48 template <typename T, size_t N>
49 void AppendBytes(T (&buf)[N]) {
50 AppendBytes(buf, N * sizeof(buf[0]));
51 }
52
53 // Support for appending padding. Does not read or write the Pad Length field.
54 void AppendZeroes(size_t num_zero_bytes);
55
56 // Append various sizes of unsigned integers.
57 void AppendUInt8(uint8_t value);
58 void AppendUInt16(uint16_t value);
59 void AppendUInt24(uint32_t value);
60 void AppendUInt31(uint32_t value);
61 void AppendUInt32(uint32_t value);
62
63 // Append various enums.
64 void Append(Http2ErrorCode error_code);
65 void Append(Http2FrameType type);
66 void Append(Http2SettingsParameter parameter);
67
68 // Append various structures.
69 void Append(const Http2FrameHeader& v);
70 void Append(const Http2PriorityFields& v);
71 void Append(const Http2RstStreamFields& v);
72 void Append(const Http2SettingFields& v);
73 void Append(const Http2PushPromiseFields& v);
74 void Append(const Http2PingFields& v);
75 void Append(const Http2GoAwayFields& v);
76 void Append(const Http2WindowUpdateFields& v);
77 void Append(const Http2AltSvcFields& v);
78
79 // Methods for changing existing buffer contents (mostly focused on updating
80 // the payload length).
81
82 void WriteAt(base::StringPiece s, size_t offset);
83 void WriteBytesAt(const void* data, uint32_t num_bytes, size_t offset);
84 void WriteUInt24At(uint32_t value, size_t offset);
85
86 // Set the payload length to the specified size.
87 void SetPayloadLength(uint32_t payload_length);
88
89 // Sets the payload length to the size of the buffer minus the size of
90 // the frame header.
91 size_t SetPayloadLength();
92
93 private:
94 std::string buffer_;
95 };
96
97 } // namespace test
98 } // namespace net
99
100 #endif // NET_HTTP2_TOOLS_HTTP2_FRAME_BUILDER_H_
OLDNEW
« no previous file with comments | « net/http2/tools/http2_bug_tracker.h ('k') | net/http2/tools/http2_frame_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698