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/util.h" | 5 #include "remoting/protocol/util.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/hash_tables.h" | 8 #include "base/hash_tables.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
12 #include "third_party/libjingle/source/talk/base/byteorder.h" | 12 #include "third_party/libjingle/source/talk/base/byteorder.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 void DeleteMessage(google::protobuf::MessageLite* message) { | 16 void DeleteMessage(google::protobuf::MessageLite* message) { |
17 delete message; | 17 delete message; |
18 } | 18 } |
19 | 19 |
20 } // namespace | 20 } // namespace |
21 | 21 |
22 namespace remoting { | 22 namespace remoting { |
| 23 namespace protocol { |
23 | 24 |
24 scoped_refptr<net::IOBufferWithSize> SerializeAndFrameMessage( | 25 scoped_refptr<net::IOBufferWithSize> SerializeAndFrameMessage( |
25 const google::protobuf::MessageLite& msg) { | 26 const google::protobuf::MessageLite& msg) { |
26 // Create a buffer with 4 extra bytes. This is used as prefix to write an | 27 // Create a buffer with 4 extra bytes. This is used as prefix to write an |
27 // int32 of the serialized message size for framing. | 28 // int32 of the serialized message size for framing. |
28 const int kExtraBytes = sizeof(int32); | 29 const int kExtraBytes = sizeof(int32); |
29 int size = msg.ByteSize() + kExtraBytes; | 30 int size = msg.ByteSize() + kExtraBytes; |
30 scoped_refptr<net::IOBufferWithSize> buffer(new net::IOBufferWithSize(size)); | 31 scoped_refptr<net::IOBufferWithSize> buffer(new net::IOBufferWithSize(size)); |
31 talk_base::SetBE32(buffer->data(), msg.GetCachedSize()); | 32 talk_base::SetBE32(buffer->data(), msg.GetCachedSize()); |
32 msg.SerializeWithCachedSizesToArray( | 33 msg.SerializeWithCachedSizesToArray( |
33 reinterpret_cast<uint8*>(buffer->data()) + kExtraBytes); | 34 reinterpret_cast<uint8*>(buffer->data()) + kExtraBytes); |
34 return buffer; | 35 return buffer; |
35 } | 36 } |
36 | 37 |
37 Task* NewDeleteMessageTask(google::protobuf::MessageLite* message) { | 38 Task* NewDeleteMessageTask(google::protobuf::MessageLite* message) { |
38 return NewRunnableFunction(&DeleteMessage, message); | 39 return NewRunnableFunction(&DeleteMessage, message); |
39 } | 40 } |
40 | 41 |
| 42 } // namespace protocol |
41 } // namespace remoting | 43 } // namespace remoting |
OLD | NEW |