/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include "dataobs_mgr_changeinfo.h" #include "securec.h" namespace OHOS { namespace AAFwk { bool ChangeInfo::Marshalling(const ChangeInfo &input, MessageParcel &data) { if (!data.WriteUint32(static_cast(input.changeType_))) { return false; } if (input.uris_.size() > std::numeric_limits::max() || !data.WriteUint32(static_cast(input.uris_.size()))) { return false; } for (auto const &uri : input.uris_) { if (!data.WriteString(uri.ToString())) { return false; } } if (!data.WriteUint32(input.size_)) { return false; } return input.size_ == 0 || data.WriteBuffer(input.data_, input.size_); } bool ChangeInfo::Unmarshalling(ChangeInfo &output, MessageParcel &parcel) { uint32_t changeType; if (!parcel.ReadUint32(changeType)) { return false; } uint32_t len = 0; if (!parcel.ReadUint32(len)) { return false; } if (len > LIST_MAX_COUNT) { return false; } std::list uris; for (uint32_t i = 0; i < len; i++) { Uri uri = Uri(parcel.ReadString()); if (uri.ToString().empty()) { return false; } uris.emplace_back(std::move(uri)); } uint32_t size = 0; if (!parcel.ReadUint32(size)) { return false; } const uint8_t *data = size > 0 ? parcel.ReadBuffer(size) : nullptr; if (size > 0 && data == nullptr) { return false; } output.changeType_ = static_cast(changeType); std::swap(output.uris_, uris); output.data_ = const_cast(data); output.size_ = size; return true; } } // namespace AAFwk } // namespace OHOS