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

Unified Diff: net/websockets/websocket_deflater.h

Issue 23623008: Implement WebSocketDeflater. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/websockets/README ('k') | net/websockets/websocket_deflater.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/websockets/websocket_deflater.h
diff --git a/net/websockets/websocket_deflater.h b/net/websockets/websocket_deflater.h
new file mode 100644
index 0000000000000000000000000000000000000000..8f2f05e7db54c7cc165386c4b437e6009d7b6578
--- /dev/null
+++ b/net/websockets/websocket_deflater.h
@@ -0,0 +1,75 @@
+// Copyright (c) 2013 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_DEFLATER_H_
+#define NET_WEBSOCKETS_WEBSOCKET_DEFLATER_H_
+
+#include <deque>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/base/net_export.h"
+
+extern "C" struct z_stream_s;
+
+namespace net {
+
+class IOBufferWithSize;
+
+class NET_EXPORT_PRIVATE WebSocketDeflater {
+ public:
+ enum ContextTakeOverMode {
+ DO_NOT_TAKE_OVER_CONTEXT,
+ TAKE_OVER_CONTEXT,
+ };
+
+ explicit WebSocketDeflater(ContextTakeOverMode mode);
+ ~WebSocketDeflater();
+
+ // Returns true if there is no error and false otherwise.
+ // This function must be called exactly once before calling any of
+ // following methods.
+ // |window_bits| must be between 8 and 15 (both inclusive).
+ bool Initialize(int window_bits);
+
+ // Adds bytes to |stream_|.
+ // Returns true if there is no error and false otherwise.
+ bool AddBytes(const char* data, size_t size);
+
+ // Flushes the current processing data.
+ // Returns true if there is no error and false otherwise.
+ bool Finish();
+
+ // Pushes "\x00\x00\xff\xff" to the end of the buffer.
+ void PushSyncMark();
+
+ // Returns the current deflated output.
+ // If the current output is larger than |size| bytes,
+ // returns the first |size| bytes of the current output.
+ // The returned bytes will be dropped from the current output and never be
+ // returned thereafter.
+ scoped_refptr<IOBufferWithSize> GetOutput(size_t size);
+
+ // Returns the size of the current deflated output.
+ size_t CurrentOutputSize() const { return buffer_.size(); }
+
+ private:
+ void ResetContext();
+ int Deflate(int flush);
+
+ scoped_ptr<z_stream_s> stream_;
+ ContextTakeOverMode mode_;
+ std::deque<char> buffer_;
+ std::vector<char> fixed_buffer_;
+ // true if bytes were added after last Finish().
+ bool are_bytes_added_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebSocketDeflater);
+};
+
+} // namespace net
+
+#endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATER_H_
« no previous file with comments | « net/websockets/README ('k') | net/websockets/websocket_deflater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698