• 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 #define MLOG_TAG "Media_Cloud_Vo"
17 
18 #include "get_check_records_vo.h"
19 
20 #include <sstream>
21 
22 #include "media_itypes_utils.h"
23 
24 namespace OHOS::Media::CloudSync {
Unmarshalling(MessageParcel & parcel)25 bool GetCheckRecordsReqBody::Unmarshalling(MessageParcel &parcel)
26 {
27     return IPC::ITypeMediaUtil::Unmarshalling(this->cloudIds, parcel);
28 }
29 
Marshalling(MessageParcel & parcel) const30 bool GetCheckRecordsReqBody::Marshalling(MessageParcel &parcel) const
31 {
32     IPC::ITypeMediaUtil::Marshalling(this->cloudIds, parcel);
33     return true;
34 }
35 
ToString() const36 std::string GetCheckRecordsReqBody::ToString() const
37 {
38     std::stringstream ss;
39     ss << "{"
40        << "\"cloudIds\": [";
41     for (size_t i = 0; i < this->cloudIds.size(); i++) {
42         ss << this->cloudIds[i];
43         if (i != this->cloudIds.size() - 1) {
44             ss << ", ";
45         }
46     }
47     ss << "]"
48        << "}";
49     return ss.str();
50 }
51 
Unmarshalling(MessageParcel & parcel)52 bool GetCheckRecordsRespBodyCheckData::Unmarshalling(MessageParcel &parcel)
53 {
54     parcel.ReadString(this->cloudId);
55     parcel.ReadInt64(this->size);
56     parcel.ReadString(this->data);
57     parcel.ReadString(this->displayName);
58     parcel.ReadString(this->fileName);
59     parcel.ReadInt32(this->mediaType);
60     parcel.ReadInt32(this->cloudVersion);
61     parcel.ReadInt32(this->position);
62     parcel.ReadInt64(this->dateModified);
63     parcel.ReadInt32(this->dirty);
64     parcel.ReadInt32(this->thmStatus);
65     parcel.ReadInt32(this->syncStatus);
66     int32_t attachmentSize;
67     parcel.ReadInt32(attachmentSize);
68     for (int32_t i = 0; i < attachmentSize; ++i) {
69         CloudFileDataVo vo;
70         std::string key;
71         parcel.ReadString(key);
72         vo.Unmarshalling(parcel);
73         this->attachment[key] = vo;
74     }
75     return true;
76 }
77 
Marshalling(MessageParcel & parcel) const78 bool GetCheckRecordsRespBodyCheckData::Marshalling(MessageParcel &parcel) const
79 {
80     parcel.WriteString(this->cloudId);
81     parcel.WriteInt64(this->size);
82     parcel.WriteString(this->data);
83     parcel.WriteString(this->displayName);
84     parcel.WriteString(this->fileName);
85     parcel.WriteInt32(this->mediaType);
86     parcel.WriteInt32(this->cloudVersion);
87     parcel.WriteInt32(this->position);
88     parcel.WriteInt64(this->dateModified);
89     parcel.WriteInt32(this->dirty);
90     parcel.WriteInt32(this->thmStatus);
91     parcel.WriteInt32(this->syncStatus);
92     parcel.WriteInt32(this->attachment.size());
93     for (auto &[key, value] : attachment) {
94         parcel.WriteString(key);
95         value.Marshalling(parcel);
96     }
97     return true;
98 }
99 
ToString() const100 std::string GetCheckRecordsRespBodyCheckData::ToString() const
101 {
102     std::stringstream ss;
103     ss << "{"
104        << "\"cloudId\": \"" << this->cloudId << "\", "
105        << "\"size\": " << this->size << ", "
106        << "\"data\": \"" << this->data << "\", "
107        << "\"mediaType\": " << this->mediaType << ", "
108        << "\"cloudVersion\": " << this->cloudVersion << ", "
109        << "\"dateModified\": " << this->dateModified << ", "
110        << "\"dirty\": " << this->dirty << "\""
111        << "\"thmStatus\": " << this->thmStatus << "\""
112        << "\"syncStatus\": " << this->syncStatus << "\"";
113     ss << ",[";
114     uint32_t index = 0;
115     for (const auto &[key, value] : attachment) {
116         ss << "{\"" << key << "\": " << value.ToString() << "}";
117         if (index != attachment.size() - 1) {
118             ss << ",";
119         }
120         index++;
121     }
122     ss << "]}";
123     return ss.str();
124 }
125 
Unmarshalling(MessageParcel & parcel)126 bool GetCheckRecordsRespBody::Unmarshalling(MessageParcel &parcel)
127 {
128     int32_t size = 0;
129     parcel.ReadInt32(size);
130     if (size <= 0) {
131         return true;
132     }
133     for (int32_t i = 0; i < size; ++i) {
134         GetCheckRecordsRespBodyCheckData data;
135         std::string key;
136         parcel.ReadString(key);
137         data.Unmarshalling(parcel);
138         this->checkDataList[key] = data;
139     }
140     return true;
141 }
142 
Marshalling(MessageParcel & parcel) const143 bool GetCheckRecordsRespBody::Marshalling(MessageParcel &parcel) const
144 {
145     parcel.WriteInt32(this->checkDataList.size());
146     for (auto [key, value] : this->checkDataList) {
147         parcel.WriteString(key);
148         if (!value.Marshalling(parcel)) {
149             return false;
150         }
151     }
152     return true;
153 }
154 
ToString() const155 std::string GetCheckRecordsRespBody::ToString() const
156 {
157     std::stringstream ss;
158     ss << "{"
159        << "\"checkDataList\": [";
160     auto it = checkDataList.begin();
161     auto endIt = checkDataList.end();
162     while (it != endIt) {
163         if (std::next(it) == endIt) {
164             ss << "{\"" << it->first << "\":" << it->second.ToString() << "}";
165         } else {
166             ss << "{\"" << it->first << "\":" << it->second.ToString() << "},";
167         }
168         ++it;
169     }
170     ss << "]"
171        << "}";
172     return ss.str();
173 }
174 }  // namespace OHOS::Media::CloudSync