1 /* 2 * Copyright (c) 2022-2023 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 #ifndef DISTRIBUTEDDATAMGR_PASTEBOARD_PARCEL_UTIL_H 17 #define DISTRIBUTEDDATAMGR_PASTEBOARD_PARCEL_UTIL_H 18 19 #include "api/visibility.h" 20 #include "parcel.h" 21 #include "securec.h" 22 #include "tlv_object.h" 23 namespace OHOS::MiscServices { 24 25 class ParcelUtil { 26 public: 27 // parcelable to buffer 28 API_EXPORT static RawMem Parcelable2Raw(const Parcelable *value); 29 30 // buffer to parcelable 31 template<typename ParcelableType> Raw2Parcelable(const RawMem & rawMem)32 static std::shared_ptr<ParcelableType> Raw2Parcelable(const RawMem &rawMem) 33 { 34 Parcel parcel(nullptr); 35 if (!Raw2Parcel(rawMem, parcel)) { 36 return nullptr; 37 } 38 return std::shared_ptr<ParcelableType>(ParcelableType::Unmarshalling(parcel)); 39 } 40 // buffer to parcelable 41 API_EXPORT static bool Raw2Parcel(const RawMem &rawMem, Parcel &parcel); 42 }; 43 } // namespace OHOS::MiscServices 44 #endif //DISTRIBUTEDDATAMGR_PASTEBOARD_PARCEL_UTIL_H 45