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 "bundle_dir.h"
17 
18 #include "nlohmann/json.hpp"
19 #include "string_ex.h"
20 
21 #include "json_util.h"
22 #include "parcel_macro.h"
23 #include <new>
24 
25 namespace OHOS {
26 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)27 bool BundleDir::ReadFromParcel(Parcel &parcel)
28 {
29     bundleName = Str16ToStr8(parcel.ReadString16());
30     appIndex = parcel.ReadInt32();
31     dir = Str16ToStr8(parcel.ReadString16());
32     return true;
33 }
34 
Unmarshalling(Parcel & parcel)35 BundleDir *BundleDir::Unmarshalling(Parcel &parcel)
36 {
37     BundleDir *bundleDir = new (std::nothrow) BundleDir();
38     if (bundleDir && !bundleDir->ReadFromParcel(parcel)) {
39         APP_LOGW("read from parcel failed");
40         delete bundleDir;
41         bundleDir = nullptr;
42     }
43     return bundleDir;
44 }
45 
Marshalling(Parcel & parcel) const46 bool BundleDir::Marshalling(Parcel &parcel) const
47 {
48     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
49     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex);
50     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(dir));
51     return true;
52 }
53 
ToString() const54 std::string BundleDir::ToString() const
55 {
56     return "[ bundleName = " + bundleName
57             + ", appIndex = " + std::to_string(appIndex)
58             + ", dir = " + dir
59             + "]";
60 }
61 }  // namespace AppExecFwk
62 }  // namespace OHOS