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 OHOS_UTILS_PARCEL_H 17 #define OHOS_UTILS_PARCEL_H 18 19 #include <string> 20 #include <vector> 21 #include "refbase.h" 22 23 namespace OHOS { 24 class Parcel; 25 26 class Parcelable : public virtual RefBase { 27 public: 28 virtual ~Parcelable() = default; 29 30 Parcelable(); 31 32 virtual bool Marshalling(Parcel &parcel) const = 0; 33 }; 34 35 class Parcel { 36 public: 37 Parcel(); 38 39 virtual ~Parcel(); 40 41 bool WriteInt32(int32_t value); 42 43 bool ReadInt32(int32_t &value); 44 45 int32_t ReadInt32(); 46 47 bool WriteUint32(uint32_t value); 48 49 bool ReadUint32(uint32_t &value); 50 51 uint32_t ReadUint32(); 52 53 bool WriteUint64(uint64_t value); 54 55 uint64_t ReadUint64(); 56 57 bool WriteFloat(float value); 58 59 float ReadFloat(); 60 61 bool WriteString(const std::string &value); 62 63 const std::string ReadString(); 64 65 bool WriteBool(bool value); 66 67 bool ReadBool(); 68 69 template<typename T> WriteObject(const sptr<T> & object)70 bool WriteObject(const sptr<T> &object) 71 { 72 return true; 73 } 74 75 template <typename T> ReadObject()76 sptr<T> ReadObject() 77 { 78 return nullptr; 79 } 80 }; 81 } // namespace OHOS 82 #endif // OHOS_UTILS_PARCEL_H 83