Index: net/websockets/websocket_frame_parser.h |
diff --git a/net/websockets/websocket_frame_parser.h b/net/websockets/websocket_frame_parser.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..496b879177a2670f8857adb27959ce9eb4cb69d0 |
--- /dev/null |
+++ b/net/websockets/websocket_frame_parser.h |
@@ -0,0 +1,65 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_WEBSOCKETS_WEBSOCKET_FRAME_PARSER_H_ |
+#define NET_WEBSOCKETS_WEBSOCKET_FRAME_PARSER_H_ |
+#pragma once |
+ |
+#include <vector> |
+ |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_vector.h" |
+#include "net/base/net_export.h" |
+#include "net/websockets/websocket_frame.h" |
+ |
+namespace net { |
+ |
+// Parses WebSocket frame data stream. |
+// |
+// Specification of WebSocket frame format is available at |
+// <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
|
+ |
+class NET_EXPORT_PRIVATE WebSocketFrameParser { |
+ public: |
+ WebSocketFrameParser(); |
+ ~WebSocketFrameParser(); |
+ |
+ // Decodes the given byte stream and stores parsed WebSocket frames in |
+ // |frames|. |
+ // |
+ // If the parser encounters invalid payload length format, Decode() fails |
+ // and returns false. Once Decode() has failed, the parser refuses to decode |
+ // any more data and future invocations of Decode() will simply return false. |
+ // |
+ // Payload data of parsed WebSocket frames may be incomplete; see comments in |
+ // websocket_frame.h for more details. |
+ bool Decode(const char* data, |
+ size_t length, |
+ ScopedVector<WebSocketPartialFrame>* frames); |
+ |
+ // Returns true if the parser has ever failed to decode a WebSocket frame. |
+ 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.
|
+ |
+ private: |
+ void DecodeFrameHeader(); |
+ |
+ // Internal buffer to store the data to parse. |
+ 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.
|
+ // Position in |buffer_| where the next round of parsing will happen. |
+ size_t buffer_pos_; |
+ |
+ // Frame header and masking key of the current frame. |
+ // |masking_key_| is filled with zeros if the current frame is not masked. |
+ scoped_refptr<WebSocketFrameHeader> current_frame_header_; |
+ char masking_key_[WebSocketFrameHeader::kMaskingKeyLength]; |
+ |
+ // Amount of payload data read so far for the current frame. |
+ uint64 frame_offset_; |
+ |
+ bool failed_; |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_PARSER_H_ |