diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-18 01:54:55 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-18 01:54:55 +0000 |
commit | e609bb94b0cf64a4373261854cfa45cfa87f6004 (patch) | |
tree | c8c18ff14831d9a2cf0ea1c7f7993c3bd35dc996 /remoting/protocol/message_decoder.h | |
parent | 7ed9caae9a7f7117d8d20bc2057d434ccf192908 (diff) | |
download | chromium_src-e609bb94b0cf64a4373261854cfa45cfa87f6004.zip chromium_src-e609bb94b0cf64a4373261854cfa45cfa87f6004.tar.gz chromium_src-e609bb94b0cf64a4373261854cfa45cfa87f6004.tar.bz2 |
Use CompoundBuffer in MessageDecoder.
TEST=Unittests
BUG=None
Review URL: http://codereview.chromium.org/5067001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66574 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/message_decoder.h')
-rw-r--r-- | remoting/protocol/message_decoder.h | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/remoting/protocol/message_decoder.h b/remoting/protocol/message_decoder.h index ea7acee..1978dc2 100644 --- a/remoting/protocol/message_decoder.h +++ b/remoting/protocol/message_decoder.h @@ -14,11 +14,6 @@ #include "remoting/base/compound_buffer.h" #include "third_party/protobuf/src/google/protobuf/message_lite.h" -namespace net { -class DrainableIOBuffer; -class IOBuffer; -} // namespace net - namespace remoting { class ChromotingClientMessage; @@ -66,18 +61,14 @@ class MessageDecoder { } private: - // TODO(sergeyu): It might be more efficient to memcopy data to one big buffer - // instead of storing chunks in dqueue. - typedef std::deque<scoped_refptr<net::DrainableIOBuffer> > BufferList; - // Parse one message from |buffer_list_|. Return true if sucessful. template <class MessageType> bool ParseOneMessage(MessageType** message) { - scoped_ptr<CompoundBuffer> buffer(CreateCompoundBufferFromData()); - if (!buffer.get()) + CompoundBuffer buffer; + if (!GetNextMessageData(&buffer)) return false; - CompoundBufferInputStream stream(buffer.get()); + CompoundBufferInputStream stream(&buffer); *message = new MessageType(); bool ret = (*message)->ParseFromZeroCopyStream(&stream); if (!ret) @@ -87,17 +78,14 @@ class MessageDecoder { void AddBuffer(scoped_refptr<net::IOBuffer> data, int data_size); - CompoundBuffer* CreateCompoundBufferFromData(); + bool GetNextMessageData(CompoundBuffer* message_buffer); // Retrieves the read payload size of the current protocol buffer via |size|. // Returns false and leaves |size| unmodified, if we do not have enough data // to retrieve the current size. bool GetPayloadSize(int* size); - BufferList buffer_list_; - - // The number of bytes in |buffer_list_| not consumed. - int available_bytes_; + CompoundBuffer buffer_; // |next_payload_| stores the size of the next payload if known. // |next_payload_known_| is true if the size of the next payload is known. |