• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "res_json_type.h"
17 
18 #include "res_sched_log.h"
19 
20 namespace OHOS {
21 namespace ResourceSchedule {
ReadFromParcel(Parcel & parcel)22 bool ResJsonType::ReadFromParcel(Parcel& parcel)
23 {
24     std::string jsonStr = parcel.ReadString();
25     return ResCommonUtil::LoadContentToJsonObj(jsonStr, jsonContext);
26 }
27 
Marshalling(Parcel & parcel) const28 bool ResJsonType::Marshalling(Parcel& parcel) const
29 {
30     std::string jsonStr = "";
31     ResCommonUtil::DumpJsonToString(jsonContext, jsonStr);
32     if (jsonStr.empty()) {
33         RESSCHED_LOGE("ResJsonType Marshalling failed, context string is empty");
34         return false;
35     }
36 
37     if (!parcel.WriteString(jsonStr)) {
38         RESSCHED_LOGE("ResJsonType Marshalling failed, content: %{public}s", jsonStr.c_str());
39         return false;
40     }
41     return true;
42 }
43 
Unmarshalling(Parcel & parcel)44 ResJsonType *ResJsonType::Unmarshalling(Parcel& parcel)
45 {
46     ResJsonType *info = new (std::nothrow) ResJsonType();
47 
48     if (info == nullptr) {
49         RESSCHED_LOGE("ResJsonType Unmarshalling failed as create null ResJsonType");
50         return nullptr;
51     }
52 
53     if (!info->ReadFromParcel(parcel)) {
54         RESSCHED_LOGE("ResJsonType Unmarshalling failed, Read from parcel faield");
55         delete info;
56         return nullptr;
57     }
58     return info;
59 }
60 } // namespace ResourceSchedule
61 } // namespace OHOS