From e609bb94b0cf64a4373261854cfa45cfa87f6004 Mon Sep 17 00:00:00 2001 From: "sergeyu@chromium.org" Date: Thu, 18 Nov 2010 01:54:55 +0000 Subject: 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 --- remoting/protocol/message_decoder.h | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'remoting/protocol/message_decoder.h') 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 > BufferList; - // Parse one message from |buffer_list_|. Return true if sucessful. template bool ParseOneMessage(MessageType** message) { - scoped_ptr 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 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. -- cgit v1.1