1 /*
2  * Copyright (C) 2021 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_remote_device_info.h"
17 #include "bluetooth_log.h"
18 
19 namespace OHOS {
20 namespace Bluetooth {
Marshalling(Parcel & parcel) const21 bool BluetoothRemoteDeviceInfo::Marshalling(Parcel &parcel) const
22 {
23     if (!parcel.WriteUint16(vendorId_)) {
24         return false;
25     }
26     if (!parcel.WriteUint16(productId_)) {
27         return false;
28     }
29     if (!parcel.WriteString(modelId_)) {
30         return false;
31     }
32     if (!parcel.WriteInt32(customType_)) {
33         return false;
34     }
35     return true;
36 }
37 
Unmarshalling(Parcel & parcel)38 BluetoothRemoteDeviceInfo *BluetoothRemoteDeviceInfo::Unmarshalling(Parcel &parcel)
39 {
40     BluetoothRemoteDeviceInfo *info = new BluetoothRemoteDeviceInfo();
41     if (info != nullptr && !info->ReadFromParcel(parcel)) {
42         delete info;
43         info = nullptr;
44     }
45     return info;
46 }
47 
WriteToParcel(Parcel & parcel)48 bool BluetoothRemoteDeviceInfo::WriteToParcel(Parcel &parcel)
49 {
50     return Marshalling(parcel);
51 }
52 
ReadFromParcel(Parcel & parcel)53 bool BluetoothRemoteDeviceInfo::ReadFromParcel(Parcel &parcel)
54 {
55     if (!parcel.ReadUint16(vendorId_)) {
56         return false;
57     }
58     if (!parcel.ReadUint16(productId_)) {
59         return false;
60     }
61     if (!parcel.ReadString(modelId_)) {
62         return false;
63     }
64     if (!parcel.ReadInt32(customType_)) {
65         return false;
66     }
67     return true;
68 }
69 }  // namespace Bluetooth
70 }  // namespace OHOS