1 /* 2 * Copyright (C) 2021-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 #include "bluetooth_bt_uuid.h" 17 #include "bluetooth_gatt_device.h" 18 #include "bluetooth_log.h" 19 #include "bluetooth_raw_address.h" 20 21 namespace OHOS { 22 namespace Bluetooth { Marshalling(Parcel & parcel) const23bool BluetoothGattDevice::Marshalling(Parcel &parcel) const 24 { 25 if (!parcel.WriteBool(isEncryption_)) { 26 return false; 27 } 28 if (!parcel.WriteUint8(transport_)) { 29 return false; 30 } 31 if (!parcel.WriteUint8(addressType_)) { 32 return false; 33 } 34 if (!parcel.WriteInt32(connectState_)) { 35 return false; 36 } 37 if (!parcel.WriteString(addr_.GetAddress())) { 38 return false; 39 } 40 return true; 41 } 42 Unmarshalling(Parcel & parcel)43BluetoothGattDevice *BluetoothGattDevice::Unmarshalling(Parcel &parcel) 44 { 45 BluetoothGattDevice *gattDevice = new BluetoothGattDevice(); 46 if (gattDevice != nullptr && !gattDevice->ReadFromParcel(parcel)) { 47 delete gattDevice; 48 gattDevice = nullptr; 49 } 50 return gattDevice; 51 } 52 WriteToParcel(Parcel & parcel)53bool BluetoothGattDevice::WriteToParcel(Parcel &parcel) 54 { 55 return Marshalling(parcel); 56 } 57 ReadFromParcel(Parcel & parcel)58bool BluetoothGattDevice::ReadFromParcel(Parcel &parcel) 59 { 60 if (!parcel.ReadBool(isEncryption_)) { 61 return false; 62 } 63 if (!parcel.ReadUint8(transport_)) { 64 return false; 65 } 66 if (!parcel.ReadUint8(addressType_)) { 67 return false; 68 } 69 if (!parcel.ReadInt32(connectState_)) { 70 return false; 71 } 72 std::string addr; 73 if (!parcel.ReadString(addr)) { 74 return false; 75 } 76 addr_ = bluetooth::RawAddress(addr); 77 return true; 78 } 79 } // namespace Bluetooth 80 } // namespace OHOS 81