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 (!parcel.WriteString(instanceKey)) {
28         return false;
29     }
30     if (token == nullptr) {
31         if (!parcel.WriteBool(false)) {
32             return false;
33         }
34     } else {
35         if (!parcel.WriteBool(true)) {
36             return false;
37         }
38         if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) {
39             return false;
40         }
41     }
42     if (preToken == nullptr) {
43         if (!parcel.WriteBool(false)) {
44             return false;
45         }
46     } else {
47         if (!parcel.WriteBool(true)) {
48             return false;
49         }
50         if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(preToken)) {
51             return false;
52         }
53     }
54     return true;
55 }
56 
ReadFromParcel(Parcel &parcel)57 bool LoadParam::ReadFromParcel(Parcel &parcel)
58 {
59     abilityRecordId = parcel.ReadInt32();
60     isShellCall = parcel.ReadBool();
61     instanceKey = parcel.ReadString();
62     if (parcel.ReadBool()) {
63         token = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
64         if (token == nullptr) {
65             return false;
66         }
67     }
68     if (parcel.ReadBool()) {
69         preToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
70         if (preToken == nullptr) {
71             return false;
72         }
73     }
74     return true;
75 }
76 
Unmarshalling(Parcel &parcel)77 LoadParam *LoadParam::Unmarshalling(Parcel &parcel)
78 {
79     LoadParam *loadParam = new (std::nothrow) LoadParam();
80     if (loadParam && !loadParam->ReadFromParcel(parcel)) {
81         delete loadParam;
82         loadParam = nullptr;
83     }
84     return loadParam;
85 }
86 }