• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "module_info.h"
17 
18 #include "nlohmann/json.hpp"
19 #include "string_ex.h"
20 
21 #include "app_log_wrapper.h"
22 #include "parcel_macro.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 
ReadFromParcel(Parcel & parcel)27 bool ModuleInfo::ReadFromParcel(Parcel &parcel)
28 {
29     moduleName = Str16ToStr8(parcel.ReadString16());
30     moduleSourceDir = Str16ToStr8(parcel.ReadString16());
31     return true;
32 }
33 
Unmarshalling(Parcel & parcel)34 ModuleInfo *ModuleInfo::Unmarshalling(Parcel &parcel)
35 {
36     ModuleInfo *info = new (std::nothrow) ModuleInfo();
37     if (info && !info->ReadFromParcel(parcel)) {
38         APP_LOGW("read from parcel failed");
39         delete info;
40         info = nullptr;
41     }
42     return info;
43 }
44 
Marshalling(Parcel & parcel) const45 bool ModuleInfo::Marshalling(Parcel &parcel) const
46 {
47     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
48     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleSourceDir));
49     return true;
50 }
51 
to_json(nlohmann::json & jsonObject,const ModuleInfo & moduleInfo)52 void to_json(nlohmann::json &jsonObject, const ModuleInfo &moduleInfo)
53 {
54     jsonObject = nlohmann::json {
55         {"moduleName", moduleInfo.moduleName},
56         {"moduleSourceDir", moduleInfo.moduleSourceDir}
57     };
58 }
59 
from_json(const nlohmann::json & jsonObject,ModuleInfo & moduleInfo)60 void from_json(const nlohmann::json &jsonObject, ModuleInfo &moduleInfo)
61 {
62     moduleInfo.moduleName = jsonObject.at("moduleName").get<std::string>();
63     moduleInfo.moduleSourceDir = jsonObject.at("moduleSourceDir").get<std::string>();
64 }
65 
66 }  // namespace AppExecFwk
67 }  // namespace OHOS
68