Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: remoting/protocol/message_serialization.h

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/message_reader_unittest.cc ('k') | remoting/protocol/monitored_video_stub.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // This file defines utility methods used for encoding and decoding the protocol 5 // This file defines utility methods used for encoding and decoding the protocol
6 // used in Chromoting. 6 // used in Chromoting.
7 7
8 #ifndef REMOTING_PROTOCOL_MESSAGE_SERIALIZATION_H_ 8 #ifndef REMOTING_PROTOCOL_MESSAGE_SERIALIZATION_H_
9 #define REMOTING_PROTOCOL_MESSAGE_SERIALIZATION_H_ 9 #define REMOTING_PROTOCOL_MESSAGE_SERIALIZATION_H_
10 10
11 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
12 #include "remoting/base/compound_buffer.h" 12 #include "remoting/base/compound_buffer.h"
13 13
14 #if defined(USE_SYSTEM_PROTOBUF) 14 #if defined(USE_SYSTEM_PROTOBUF)
15 #include <google/protobuf/message_lite.h> 15 #include <google/protobuf/message_lite.h>
16 #else 16 #else
17 #include "third_party/protobuf/src/google/protobuf/message_lite.h" 17 #include "third_party/protobuf/src/google/protobuf/message_lite.h"
18 #endif 18 #endif
19 19
20 namespace remoting { 20 namespace remoting {
21 namespace protocol { 21 namespace protocol {
22 22
23 template <class T> 23 template <class T>
24 scoped_ptr<T> ParseMessage(CompoundBuffer* buffer) { 24 std::unique_ptr<T> ParseMessage(CompoundBuffer* buffer) {
25 scoped_ptr<T> message(new T()); 25 std::unique_ptr<T> message(new T());
26 CompoundBufferInputStream stream(buffer); 26 CompoundBufferInputStream stream(buffer);
27 if (!message->ParseFromZeroCopyStream(&stream)) { 27 if (!message->ParseFromZeroCopyStream(&stream)) {
28 LOG(WARNING) << "Received message that is not a valid protocol buffer."; 28 LOG(WARNING) << "Received message that is not a valid protocol buffer.";
29 return nullptr; 29 return nullptr;
30 } 30 }
31 DCHECK_EQ(stream.position(), buffer->total_bytes()); 31 DCHECK_EQ(stream.position(), buffer->total_bytes());
32 return message; 32 return message;
33 } 33 }
34 34
35 // Serialize the Protocol Buffer message and provide sufficient framing for 35 // Serialize the Protocol Buffer message and provide sufficient framing for
36 // sending it over the wire. 36 // sending it over the wire.
37 // This will provide sufficient prefix and suffix for the receiver side to 37 // This will provide sufficient prefix and suffix for the receiver side to
38 // decode the message. 38 // decode the message.
39 scoped_refptr<net::IOBufferWithSize> SerializeAndFrameMessage( 39 scoped_refptr<net::IOBufferWithSize> SerializeAndFrameMessage(
40 const google::protobuf::MessageLite& msg); 40 const google::protobuf::MessageLite& msg);
41 41
42 } // namespace protocol 42 } // namespace protocol
43 } // namespace remoting 43 } // namespace remoting
44 44
45 #endif // REMOTING_PROTOCOL_MESSAGE_SERIALIZATION_H_ 45 #endif // REMOTING_PROTOCOL_MESSAGE_SERIALIZATION_H_
OLDNEW
« no previous file with comments | « remoting/protocol/message_reader_unittest.cc ('k') | remoting/protocol/monitored_video_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698