| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/protocol/message_decoder.h" | 5 #include "remoting/protocol/message_decoder.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 9 #include "remoting/base/compound_buffer.h" | 9 #include "remoting/base/compound_buffer.h" |
| 10 #include "remoting/proto/internal.pb.h" | 10 #include "remoting/proto/internal.pb.h" |
| 11 #include "third_party/libjingle/source/talk/base/byteorder.h" | 11 #include "third_party/libjingle/source/talk/base/byteorder.h" |
| 12 | 12 |
| 13 namespace remoting { | 13 namespace remoting { |
| 14 namespace protocol { | 14 namespace protocol { |
| 15 | 15 |
| 16 MessageDecoder::MessageDecoder() | 16 MessageDecoder::MessageDecoder() |
| 17 : next_payload_(0), | 17 : next_payload_(0), |
| 18 next_payload_known_(false) { | 18 next_payload_known_(false) { |
| 19 } | 19 } |
| 20 | 20 |
| 21 MessageDecoder::~MessageDecoder() {} | 21 MessageDecoder::~MessageDecoder() {} |
| 22 | 22 |
| 23 void MessageDecoder::AddBuffer(scoped_refptr<net::IOBuffer> data, | 23 void MessageDecoder::AddData(scoped_refptr<net::IOBuffer> data, |
| 24 int data_size) { | 24 int data_size) { |
| 25 buffer_.Append(data, data_size); | 25 buffer_.Append(data, data_size); |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool MessageDecoder::GetNextMessageData(CompoundBuffer* message_buffer) { | 28 bool MessageDecoder::GetNextMessage(CompoundBuffer* message_buffer) { |
| 29 // Determine the payload size. If we already know it then skip this part. | 29 // Determine the payload size. If we already know it then skip this part. |
| 30 // We may not have enough data to determine the payload size so use a | 30 // We may not have enough data to determine the payload size so use a |
| 31 // utility function to find out. | 31 // utility function to find out. |
| 32 int next_payload = -1; | 32 int next_payload = -1; |
| 33 if (!next_payload_known_ && GetPayloadSize(&next_payload)) { | 33 if (!next_payload_known_ && GetPayloadSize(&next_payload)) { |
| 34 DCHECK_NE(-1, next_payload); | 34 DCHECK_NE(-1, next_payload); |
| 35 next_payload_ = next_payload; | 35 next_payload_ = next_payload; |
| 36 next_payload_known_ = true; | 36 next_payload_known_ = true; |
| 37 } | 37 } |
| 38 | 38 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 60 char header[kHeaderSize]; | 60 char header[kHeaderSize]; |
| 61 header_buffer.CopyFrom(buffer_, 0, kHeaderSize); | 61 header_buffer.CopyFrom(buffer_, 0, kHeaderSize); |
| 62 header_buffer.CopyTo(header, kHeaderSize); | 62 header_buffer.CopyTo(header, kHeaderSize); |
| 63 *size = talk_base::GetBE32(header); | 63 *size = talk_base::GetBE32(header); |
| 64 buffer_.CropFront(kHeaderSize); | 64 buffer_.CropFront(kHeaderSize); |
| 65 return true; | 65 return true; |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace protocol | 68 } // namespace protocol |
| 69 } // namespace remoting | 69 } // namespace remoting |
| OLD | NEW |