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

Side by Side Diff: net/websockets/websocket_frame_parser.h

Issue 9956013: Add WebSocketFrameParser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_WEBSOCKETS_WEBSOCKET_FRAME_PARSER_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_FRAME_PARSER_H_
7 #pragma once
8
9 #include <vector>
10
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_vector.h"
13 #include "net/base/net_export.h"
14 #include "net/websockets/websocket_frame.h"
15
16 namespace net {
17
18 // Parses WebSocket frame data stream.
19 //
20 // Specification of WebSocket frame format is available at
21 // <http://tools.ietf.org/html/rfc6455#section-5>.
Takashi Toyoshima 2012/04/04 05:46:21 ditto.
Takashi Toyoshima 2012/04/09 23:12:16 How about this? You fixed the first one. So I gues
Yuta Kitamura 2012/04/10 05:34:00 I actually didn't fixed the other one either (I ju
22
23 class NET_EXPORT_PRIVATE WebSocketFrameParser {
24 public:
25 WebSocketFrameParser();
26 ~WebSocketFrameParser();
27
28 // Decodes the given byte stream and stores parsed WebSocket frames in
29 // |frames|.
30 //
31 // If the parser encounters invalid payload length format, Decode() fails
32 // and returns false. Once Decode() has failed, the parser refuses to decode
33 // any more data and future invocations of Decode() will simply return false.
34 //
35 // Payload data of parsed WebSocket frames may be incomplete; see comments in
36 // websocket_frame.h for more details.
37 bool Decode(const char* data,
38 size_t length,
39 ScopedVector<WebSocketPartialFrame>* frames);
40
41 // Returns true if the parser has ever failed to decode a WebSocket frame.
42 bool failed() const;
Takashi Toyoshima 2012/04/04 05:46:21 This kind of getter will be implemented here.
Yuta Kitamura 2012/04/09 08:17:57 Will fix.
43
44 private:
45 void DecodeFrameHeader();
46
47 // Internal buffer to store the data to parse.
48 std::vector<char> buffer_;
Takashi Toyoshima 2012/04/04 05:46:21 blank line is needed between line 48 and 49.
Yuta Kitamura 2012/04/09 08:17:57 Will fix.
49 // Position in |buffer_| where the next round of parsing will happen.
50 size_t buffer_pos_;
51
52 // Frame header and masking key of the current frame.
53 // |masking_key_| is filled with zeros if the current frame is not masked.
54 scoped_refptr<WebSocketFrameHeader> current_frame_header_;
55 char masking_key_[WebSocketFrameHeader::kMaskingKeyLength];
56
57 // Amount of payload data read so far for the current frame.
58 uint64 frame_offset_;
59
60 bool failed_;
61 };
62
63 } // namespace net
64
65 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698