1 /* 2 * Copyright (c) 2022 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 Raw2Parcelable(const RawMem & rawMem)31 template<typename ParcelableType> static std::shared_ptr<ParcelableType> Raw2Parcelable(const RawMem &rawMem) 32 { 33 Parcel parcel(nullptr); 34 if (!Raw2Parcel(rawMem, parcel)) { 35 return nullptr; 36 } 37 return std::shared_ptr<ParcelableType>(ParcelableType::Unmarshalling(parcel)); 38 } 39 // buffer to parcelable 40 API_EXPORT static bool Raw2Parcel(const RawMem &rawMem, Parcel &parcel); 41 }; 42 } // namespace OHOS::MiscServices 43 #endif //DISTRIBUTEDDATAMGR_PASTEBOARD_PARCEL_UTIL_H 44