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

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

Issue 1654513003: Simplify message parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no_done
Patch Set: Created 4 years, 10 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
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 13
13 #if defined(USE_SYSTEM_PROTOBUF) 14 #if defined(USE_SYSTEM_PROTOBUF)
14 #include <google/protobuf/message_lite.h> 15 #include <google/protobuf/message_lite.h>
15 #else 16 #else
16 #include "third_party/protobuf/src/google/protobuf/message_lite.h" 17 #include "third_party/protobuf/src/google/protobuf/message_lite.h"
17 #endif 18 #endif
18 19
19 namespace remoting { 20 namespace remoting {
20 namespace protocol { 21 namespace protocol {
21 22
23 template <class T>
24 scoped_ptr<T> ParseMessage(CompoundBuffer* buffer) {
25 scoped_ptr<T> message(new T());
26 CompoundBufferInputStream stream(buffer);
27 if (!message->ParseFromZeroCopyStream(&stream)) {
28 LOG(WARNING) << "Received message that is not a valid protocol buffer.";
29 return nullptr;
30 }
31 DCHECK_EQ(stream.position(), buffer->total_bytes());
32 return message;
33 }
34
22 // Serialize the Protocol Buffer message and provide sufficient framing for 35 // Serialize the Protocol Buffer message and provide sufficient framing for
23 // sending it over the wire. 36 // sending it over the wire.
24 // 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
25 // decode the message. 38 // decode the message.
26 scoped_refptr<net::IOBufferWithSize> SerializeAndFrameMessage( 39 scoped_refptr<net::IOBufferWithSize> SerializeAndFrameMessage(
27 const google::protobuf::MessageLite& msg); 40 const google::protobuf::MessageLite& msg);
28 41
29 } // namespace protocol 42 } // namespace protocol
30 } // namespace remoting 43 } // namespace remoting
31 44
32 #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/protobuf_message_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698