1 // Copyright 2013 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 "google_apis/gcm/base/mcs_message.h"
7 #include "base/logging.h"
8 #include "google_apis/gcm/base/mcs_util.h"
12 MCSMessage::Core::Core() {}
14 MCSMessage::Core::Core(uint8 tag
,
15 const google::protobuf::MessageLite
& protobuf
) {
16 scoped_ptr
<google::protobuf::MessageLite
> owned_protobuf(protobuf
.New());
17 owned_protobuf
->CheckTypeAndMergeFrom(protobuf
);
18 protobuf_
= owned_protobuf
.Pass();
21 MCSMessage::Core::Core(
23 scoped_ptr
<const google::protobuf::MessageLite
> protobuf
) {
24 protobuf_
= protobuf
.Pass();
27 MCSMessage::Core::~Core() {}
29 const google::protobuf::MessageLite
& MCSMessage::Core::Get() const {
33 MCSMessage::MCSMessage() : tag_(0), size_(0) {}
35 MCSMessage::MCSMessage(const google::protobuf::MessageLite
& protobuf
)
36 : tag_(GetMCSProtoTag(protobuf
)),
37 size_(protobuf
.ByteSize()),
38 core_(new Core(tag_
, protobuf
)) {
41 MCSMessage::MCSMessage(uint8 tag
,
42 const google::protobuf::MessageLite
& protobuf
)
44 size_(protobuf
.ByteSize()),
45 core_(new Core(tag_
, protobuf
)) {
46 DCHECK_EQ(tag
, GetMCSProtoTag(protobuf
));
49 MCSMessage::MCSMessage(uint8 tag
,
50 scoped_ptr
<const google::protobuf::MessageLite
> protobuf
)
52 size_(protobuf
->ByteSize()),
53 core_(new Core(tag_
, protobuf
.Pass())) {
54 DCHECK_EQ(tag
, GetMCSProtoTag(core_
->Get()));
57 MCSMessage::~MCSMessage() {
60 bool MCSMessage::IsValid() const {
61 return core_
.get() != NULL
;
64 std::string
MCSMessage::SerializeAsString() const {
65 return core_
->Get().SerializeAsString();
68 const google::protobuf::MessageLite
& MCSMessage::GetProtobuf() const {
72 scoped_ptr
<google::protobuf::MessageLite
> MCSMessage::CloneProtobuf() const {
73 scoped_ptr
<google::protobuf::MessageLite
> clone(GetProtobuf().New());
74 clone
->CheckTypeAndMergeFrom(GetProtobuf());