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/multiple_array_input_stream.h" | 9 #include "remoting/base/multiple_array_input_stream.h" |
10 #include "remoting/proto/internal.pb.h" | 10 #include "remoting/proto/internal.pb.h" |
11 #include "talk/base/byteorder.h" | 11 #include "talk/base/byteorder.h" |
12 | 12 |
13 namespace remoting { | 13 namespace remoting { |
14 | 14 |
15 MessageDecoder::MessageDecoder() | 15 MessageDecoder::MessageDecoder() |
16 : available_bytes_(0), | 16 : available_bytes_(0), |
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::AddBuffer(scoped_refptr<net::IOBuffer> data, |
24 int data_size) { | 24 int data_size) { |
25 buffer_list_.push_back(new net::DrainableIOBuffer(data, data_size)); | 25 buffer_list_.push_back(make_scoped_refptr( |
| 26 new net::DrainableIOBuffer(data, data_size))); |
26 available_bytes_ += data_size; | 27 available_bytes_ += data_size; |
27 } | 28 } |
28 | 29 |
29 MultipleArrayInputStream* MessageDecoder::CreateInputStreamFromData() { | 30 MultipleArrayInputStream* MessageDecoder::CreateInputStreamFromData() { |
30 // Determine the payload size. If we already know it then skip this part. | 31 // Determine the payload size. If we already know it then skip this part. |
31 // We may not have enough data to determine the payload size so use a | 32 // We may not have enough data to determine the payload size so use a |
32 // utility function to find out. | 33 // utility function to find out. |
33 int next_payload = -1; | 34 int next_payload = -1; |
34 if (!next_payload_known_ && GetPayloadSize(&next_payload)) { | 35 if (!next_payload_known_ && GetPayloadSize(&next_payload)) { |
35 DCHECK_NE(-1, next_payload); | 36 DCHECK_NE(-1, next_payload); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 if (!buffer->BytesRemaining()) { | 104 if (!buffer->BytesRemaining()) { |
104 buffer_list_.pop_front(); | 105 buffer_list_.pop_front(); |
105 } | 106 } |
106 } | 107 } |
107 | 108 |
108 *size = talk_base::GetBE32(header.c_str()); | 109 *size = talk_base::GetBE32(header.c_str()); |
109 return true; | 110 return true; |
110 } | 111 } |
111 | 112 |
112 } // namespace remoting | 113 } // namespace remoting |
OLD | NEW |