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 #define MLOG_TAG "Media_Cloud_Vo"
17
18 #include "on_fetch_records_vo.h"
19
20 #include <sstream>
21
22 #include "media_itypes_utils.h"
23 #include "cloud_media_sync_const.h"
24 #include "media_log.h"
25
26 namespace OHOS::Media::CloudSync {
Unmarshalling(MessageParcel & parcel)27 bool OnFetchRecordsReqBody::Unmarshalling(MessageParcel &parcel)
28 {
29 return IPC::ITypeMediaUtil::UnmarshallingParcelable<OnFetchPhotosVo>(this->onFetchPhotos, parcel);
30 }
31
Marshalling(MessageParcel & parcel) const32 bool OnFetchRecordsReqBody::Marshalling(MessageParcel &parcel) const
33 {
34 return IPC::ITypeMediaUtil::MarshallingParcelable<OnFetchPhotosVo>(this->onFetchPhotos, parcel);
35 }
36
AddOnFetchPhotoData(const OnFetchPhotosVo & data)37 int32_t OnFetchRecordsReqBody::AddOnFetchPhotoData(const OnFetchPhotosVo &data)
38 {
39 this->onFetchPhotos.push_back(data);
40 return 0;
41 }
42
GetOnFetchPhotoData()43 std::vector<OnFetchPhotosVo> OnFetchRecordsReqBody::GetOnFetchPhotoData()
44 {
45 return onFetchPhotos;
46 }
47
ToString() const48 std::string OnFetchRecordsReqBody::ToString() const
49 {
50 std::stringstream ss;
51 return ss.str();
52 }
53
Unmarshalling(MessageParcel & parcel)54 bool OnFetchRecordsRespBody::Unmarshalling(MessageParcel &parcel)
55 {
56 CHECK_AND_RETURN_RET(IPC::ITypeMediaUtil::Unmarshalling<std::string>(this->failedRecords, parcel), false);
57 CHECK_AND_RETURN_RET(IPC::ITypeMediaUtil::UnmarshallingParcelable<PhotosVo>(this->newDatas, parcel), false);
58 CHECK_AND_RETURN_RET(IPC::ITypeMediaUtil::UnmarshallingParcelable<PhotosVo>(this->fdirtyDatas, parcel), false);
59 return IPC::ITypeMediaUtil::Unmarshalling<int32_t>(this->stats, parcel);
60 }
61
Marshalling(MessageParcel & parcel) const62 bool OnFetchRecordsRespBody::Marshalling(MessageParcel &parcel) const
63 {
64 CHECK_AND_RETURN_RET(IPC::ITypeMediaUtil::Marshalling<std::string>(this->failedRecords, parcel), false);
65 CHECK_AND_RETURN_RET(IPC::ITypeMediaUtil::MarshallingParcelable<PhotosVo>(this->newDatas, parcel), false);
66 CHECK_AND_RETURN_RET(IPC::ITypeMediaUtil::MarshallingParcelable<PhotosVo>(this->fdirtyDatas, parcel), false);
67 return IPC::ITypeMediaUtil::Marshalling<int32_t>(this->stats, parcel);
68 }
69
ToString() const70 std::string OnFetchRecordsRespBody::ToString() const
71 {
72 std::stringstream ss;
73 ss << "{"
74 << "\"stats\":[" << stats[StatsIndex::NEW_RECORDS_COUNT] << "," << stats[StatsIndex::MERGE_RECORDS_COUNT] << ","
75 << stats[StatsIndex::META_MODIFY_RECORDS_COUNT] << "," << stats[StatsIndex::FILE_MODIFY_RECORDS_COUNT] << ","
76 << stats[StatsIndex::DELETE_RECORDS_COUNT] << "],\"newDatas\":[";
77 for (uint32_t i = 0; i < newDatas.size(); i++) {
78 if (i != newDatas.size() - 1) {
79 ss << newDatas[i].ToString() << ",";
80 continue;
81 }
82 ss << newDatas[i].ToString();
83 }
84 ss << "],\"fdirtyDatas\": [";
85 for (uint32_t i = 0; i < fdirtyDatas.size(); i++) {
86 if (i != fdirtyDatas.size() - 1) {
87 ss << fdirtyDatas[i].ToString() << ",";
88 continue;
89 }
90 ss << fdirtyDatas[i].ToString();
91 }
92 ss << "],\"failedRecords\": [";
93 for (uint32_t i = 0; i < failedRecords.size(); i++) {
94 if (i != failedRecords.size() - 1) {
95 ss << failedRecords[i] << ",";
96 continue;
97 }
98 ss << failedRecords[i];
99 }
100 ss << "]}";
101 return ss.str();
102 }
103 } // namespace OHOS::Media::CloudSync