Fix an issue that a browser seek is requested after decoder draining is interrupted.
[chromium-blink-merge.git] / remoting / protocol / message_serialization.cc
blob435baf94cfa8e9bd16593ae2fa7793a635b76b98
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
3 // found in the LICENSE file.
5 #include "remoting/protocol/message_serialization.h"
7 #include "base/basictypes.h"
8 #include "base/containers/hash_tables.h"
9 #include "base/logging.h"
10 #include "net/base/io_buffer.h"
11 #include "third_party/webrtc/base/byteorder.h"
13 namespace remoting {
14 namespace protocol {
16 scoped_refptr<net::IOBufferWithSize> SerializeAndFrameMessage(
17 const google::protobuf::MessageLite& msg) {
18 // Create a buffer with 4 extra bytes. This is used as prefix to write an
19 // int32 of the serialized message size for framing.
20 const int kExtraBytes = sizeof(int32);
21 int size = msg.ByteSize() + kExtraBytes;
22 scoped_refptr<net::IOBufferWithSize> buffer(new net::IOBufferWithSize(size));
23 rtc::SetBE32(buffer->data(), msg.GetCachedSize());
24 msg.SerializeWithCachedSizesToArray(
25 reinterpret_cast<uint8*>(buffer->data()) + kExtraBytes);
26 return buffer;
29 } // namespace protocol
30 } // namespace remoting