• 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 "photos_vo.h"
19 
20 #include <sstream>
21 
22 #include "media_itypes_utils.h"
23 #include "media_log.h"
24 
25 namespace OHOS::Media::CloudSync {
Unmarshalling(MessageParcel & parcel)26 bool PhotosVo::Unmarshalling(MessageParcel &parcel)
27 {
28     parcel.ReadInt32(this->fileId);
29     parcel.ReadString(this->cloudId);
30     parcel.ReadInt64(this->size);
31     parcel.ReadInt64(this->modifiedTime);
32     parcel.ReadString(this->path);
33     parcel.ReadString(this->fileName);
34     parcel.ReadString(this->originalCloudId);
35     parcel.ReadInt32(this->type);
36     parcel.ReadInt32(this->orientation);
37     CloudFileDataVo::Unmarshalling(this->attachment, parcel);
38     return true;
39 }
40 
Marshalling(MessageParcel & parcel) const41 bool PhotosVo::Marshalling(MessageParcel &parcel) const
42 {
43     parcel.WriteInt32(this->fileId);
44     parcel.WriteString(this->cloudId);
45     parcel.WriteInt64(this->size);
46     parcel.WriteInt64(this->modifiedTime);
47     parcel.WriteString(this->path);
48     parcel.WriteString(this->fileName);
49     parcel.WriteString(this->originalCloudId);
50     parcel.WriteInt32(this->type);
51     parcel.WriteInt32(this->orientation);
52     CloudFileDataVo::Marshalling(this->attachment, parcel);
53     return true;
54 }
55 
Marshalling(const std::vector<PhotosVo> & result,MessageParcel & parcel)56 bool PhotosVo::Marshalling(const std::vector<PhotosVo> &result, MessageParcel &parcel)
57 {
58     CHECK_AND_RETURN_RET(parcel.WriteInt32(static_cast<int32_t>(result.size())), false);
59     for (const auto &entry : result) {
60         if (!entry.Marshalling(parcel)) {
61             return false;
62         }
63     }
64     return true;
65 }
66 
Unmarshalling(std::vector<PhotosVo> & val,MessageParcel & parcel)67 bool PhotosVo::Unmarshalling(std::vector<PhotosVo> &val, MessageParcel &parcel)
68 {
69     int32_t len = parcel.ReadInt32();
70     CHECK_AND_RETURN_RET(len >= 0, false);
71 
72     size_t readAbleSize = parcel.GetReadableBytes();
73     size_t size = static_cast<size_t>(len);
74     if ((size > readAbleSize) || (size > val.max_size())) {
75         return false;
76     }
77 
78     val.clear();
79     bool isValid;
80     for (size_t i = 0; i < size; i++) {
81         PhotosVo nodeObj;
82         isValid = nodeObj.Unmarshalling(parcel);
83         CHECK_AND_RETURN_RET(isValid, false);
84         val.emplace_back(nodeObj);
85     }
86     return true;
87 }
88 
ToString(std::map<std::string,CloudFileDataVo> dataMap) const89 std::string PhotosVo::ToString(std::map<std::string, CloudFileDataVo> dataMap) const
90 {
91     std::stringstream ss;
92     bool first = true;
93     for (auto &node : dataMap) {
94         if (!first) {
95             ss << ", ";
96         }
97         ss << "\"" << node.first << "\": " << node.second.ToString();
98         first = false;
99     }
100     return ss.str();
101 }
102 
ToString() const103 std::string PhotosVo::ToString() const
104 {
105     std::stringstream ss;
106     ss << "{"
107        << "\"fileId\": " << this->fileId << ", "
108        << "\"cloudId\": \"" << this->cloudId << "\", "
109        << "\"originalCloudId\": \"" << this->originalCloudId << "\", "
110        << "\"size\": " << this->size << ", "
111        << "\"modifiedTime\": " << this->modifiedTime << ", "
112        << "\"type\": " << this->type << ", "
113        << "\"attachment\": {" << this->ToString(this->attachment) << "}"
114        << "}";
115     return ss.str();
116 }
117 }  // namespace OHOS::Media::CloudSync