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 "param.h"
17 
18 namespace OHOS::AbilityRuntime {
Marshalling(Parcel & parcel) const19 bool LoadParam::Marshalling(Parcel &parcel) const
20 {
21     if (!parcel.WriteInt32(abilityRecordId)) {
22         return false;
23     }
24     if (!parcel.WriteBool(isShellCall)) {
25         return false;
26     }
27     if (token == nullptr) {
28         if (!parcel.WriteBool(false)) {
29             return false;
30         }
31     } else {
32         if (!parcel.WriteBool(true)) {
33             return false;
34         }
35         if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) {
36             return false;
37         }
38     }
39     if (preToken == nullptr) {
40         if (!parcel.WriteBool(false)) {
41             return false;
42         }
43     } else {
44         if (!parcel.WriteBool(true)) {
45             return false;
46         }
47         if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(preToken)) {
48             return false;
49         }
50     }
51     return true;
52 }
53 
ReadFromParcel(Parcel & parcel)54 bool LoadParam::ReadFromParcel(Parcel &parcel)
55 {
56     abilityRecordId = parcel.ReadInt32();
57     isShellCall = parcel.ReadBool();
58     if (parcel.ReadBool()) {
59         token = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
60         if (token == nullptr) {
61             return false;
62         }
63     }
64     if (parcel.ReadBool()) {
65         preToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
66         if (preToken == nullptr) {
67             return false;
68         }
69     }
70     return true;
71 }
72 
Unmarshalling(Parcel & parcel)73 LoadParam *LoadParam::Unmarshalling(Parcel &parcel)
74 {
75     LoadParam *loadParam = new (std::nothrow) LoadParam();
76     if (loadParam && !loadParam->ReadFromParcel(parcel)) {
77         delete loadParam;
78         loadParam = nullptr;
79     }
80     return loadParam;
81 }
82 }