1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "account_log_wrapper.h"
17 #include "distributed_account_subscribe_callback.h"
18 
19 namespace OHOS {
20 namespace AccountSA {
21 
Marshalling(Parcel & parcel) const22 bool DistributedAccountEventData::Marshalling(Parcel &parcel) const
23 {
24     if (!parcel.WriteInt32(id_)) {
25         ACCOUNT_LOGE("Write id failed.");
26         return false;
27     }
28     if (!parcel.WriteInt32(static_cast<int32_t>(type_))) {
29         ACCOUNT_LOGE("Write type failed.");
30         return false;
31     }
32     return true;
33 }
34 
Unmarshalling(Parcel & parcel)35 DistributedAccountEventData *DistributedAccountEventData::Unmarshalling(Parcel &parcel)
36 {
37     DistributedAccountEventData *eventData = new (std::nothrow) DistributedAccountEventData();
38 
39     if (eventData != nullptr && !eventData->ReadFromParcel(parcel)) {
40         ACCOUNT_LOGE("Read from parcel failed.");
41         delete eventData;
42         eventData = nullptr;
43     }
44 
45     return eventData;
46 }
47 
operator ==(const DistributedAccountEventData & eventData) const48 bool DistributedAccountEventData::operator==(const DistributedAccountEventData &eventData) const
49 {
50     return (this->id_ == eventData.id_) && (this->type_ == eventData.type_);
51 }
52 
ReadFromParcel(Parcel & parcel)53 bool DistributedAccountEventData::ReadFromParcel(Parcel &parcel)
54 {
55     int32_t id = 0;
56     if (!parcel.ReadInt32(id)) {
57         ACCOUNT_LOGE("Read id failed.");
58         return false;
59     }
60     id_ = id;
61     int32_t type = 0;
62     if (!parcel.ReadInt32(type)) {
63         ACCOUNT_LOGE("Read type failed.");
64         return false;
65     }
66     type_ = static_cast<DISTRIBUTED_ACCOUNT_SUBSCRIBE_TYPE>(type);
67 
68     return true;
69 }
70 }  // namespace AccountSA
71 }  // namespace OHOS
72