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_copy_records_photos_vo.h"
19
20 #include <sstream>
21
22 #include "media_itypes_utils.h"
23
24 namespace OHOS::Media::CloudSync {
25
Unmarshalling(MessageParcel & parcel)26 bool OnCopyRecord::Unmarshalling(MessageParcel &parcel)
27 {
28 parcel.ReadString(this->cloudId);
29 parcel.ReadInt32(this->fileId);
30 parcel.ReadInt32(this->rotation);
31 parcel.ReadInt32(this->fileType);
32 parcel.ReadInt64(this->size);
33 parcel.ReadInt64(this->createTime);
34 parcel.ReadString(this->path);
35 parcel.ReadString(this->fileName);
36 parcel.ReadString(this->sourcePath);
37 parcel.ReadInt64(this->version);
38 parcel.ReadInt32(this->serverErrorCode);
39 parcel.ReadBool(this->isSuccess);
40 IPC::ITypeMediaUtil::UnmarshallingParcelable<CloudErrorDetail>(this->errorDetails, parcel);
41 int32_t copyRecordErrorType;
42 parcel.ReadInt32(copyRecordErrorType);
43 this->errorType = static_cast<ErrorType>(copyRecordErrorType);
44 return true;
45 }
Marshalling(MessageParcel & parcel) const46 bool OnCopyRecord::Marshalling(MessageParcel &parcel) const
47 {
48 parcel.WriteString(this->cloudId);
49 parcel.WriteInt32(this->fileId);
50 parcel.WriteInt32(this->rotation);
51 parcel.WriteInt32(this->fileType);
52 parcel.WriteInt64(this->size);
53 parcel.WriteInt64(this->createTime);
54 parcel.WriteString(this->path);
55 parcel.WriteString(this->fileName);
56 parcel.WriteString(this->sourcePath);
57 parcel.WriteInt64(this->version);
58 parcel.WriteInt32(this->serverErrorCode);
59 parcel.WriteBool(this->isSuccess);
60 IPC::ITypeMediaUtil::MarshallingParcelable<CloudErrorDetail>(this->errorDetails, parcel);
61 parcel.WriteInt32(static_cast<int32_t>(this->errorType));
62 return true;
63 }
64
ToString() const65 std::string OnCopyRecord::ToString() const
66 {
67 std::stringstream ss;
68 ss << "{"
69 << "\"cloudId\": \"" << cloudId << "\","
70 << "\"fileId\": " << fileId << ","
71 << "\"rotation\": " << rotation << ","
72 << "\"fileType\": " << fileType << ","
73 << "\"size\": " << size << ","
74 << "\"createTime\": " << createTime << ","
75 << "\"path\": \"" << path << "\","
76 << "\"version\": " << version << ","
77 << "\"serverErrorCode\": " << serverErrorCode << ","
78 << "\"isSuccess\": " << std::to_string(isSuccess) << ","
79 << "\"errorType\": " << static_cast<int32_t>(errorType) << ""
80 << "}";
81 return ss.str();
82 }
83
Unmarshalling(MessageParcel & parcel)84 bool OnCopyRecordsPhotosReqBody::Unmarshalling(MessageParcel &parcel)
85 {
86 return IPC::ITypeMediaUtil::UnmarshallingParcelable(this->records, parcel);
87 }
88
Marshalling(MessageParcel & parcel) const89 bool OnCopyRecordsPhotosReqBody::Marshalling(MessageParcel &parcel) const
90 {
91 IPC::ITypeMediaUtil::MarshallingParcelable(this->records, parcel);
92 return true;
93 }
94
AddCopyRecord(const OnCopyRecord & record)95 int32_t OnCopyRecordsPhotosReqBody::AddCopyRecord(const OnCopyRecord &record)
96 {
97 this->records.push_back(record);
98 return E_OK;
99 }
100
GetRecords()101 std::vector<OnCopyRecord> OnCopyRecordsPhotosReqBody::GetRecords()
102 {
103 return records;
104 }
105
ToString() const106 std::string OnCopyRecordsPhotosReqBody::ToString() const
107 {
108 std::stringstream ss;
109 ss << "{\"records\":[";
110 for (uint32_t i = 0; i < records.size(); ++i) {
111 if (i != records.size() - 1) {
112 ss << records[i].ToString() << ",";
113 continue;
114 }
115 ss << records[i].ToString();
116 }
117 ss << "]}";
118 return ss.str();
119 }
120 } // namespace OHOS::Media::CloudSync