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 #include "bluetooth_avrcp_mpItem.h" 17 18 namespace OHOS { 19 namespace Bluetooth { 20 const uint32_t AVRCP_READ_FROM_PARCEL_COUNT_MAX = 0xFFFF; Marshalling(Parcel & parcel) const21bool BluetoothAvrcpMpItem::Marshalling(Parcel &parcel) const 22 { 23 if (!parcel.WriteUint8(itemType_)) { 24 return false; 25 } 26 if (!parcel.WriteUint16(playerId_)) { 27 return false; 28 } 29 if (!parcel.WriteUint8(majorType_)) { 30 return false; 31 } 32 if (!parcel.WriteUint32(subType_)) { 33 return false; 34 } 35 if (!parcel.WriteUint8(playStatus_)) { 36 return false; 37 } 38 if (!parcel.WriteUint32(features_.size())) { 39 return false; 40 } 41 for (auto &feature : features_) { 42 if (!parcel.WriteUint8(feature)) { 43 return false; 44 } 45 } 46 if (!parcel.WriteString(name_)) { 47 return false; 48 } 49 return true; 50 } 51 WriteToParcel(Parcel & parcel)52bool BluetoothAvrcpMpItem::WriteToParcel(Parcel &parcel) 53 { 54 return Marshalling(parcel); 55 } 56 Unmarshalling(Parcel & parcel)57BluetoothAvrcpMpItem *BluetoothAvrcpMpItem::Unmarshalling(Parcel &parcel) 58 { 59 BluetoothAvrcpMpItem *avrcpData = new BluetoothAvrcpMpItem(); 60 if (avrcpData != nullptr && !avrcpData->ReadFromParcel(parcel)) { 61 delete avrcpData; 62 avrcpData = nullptr; 63 } 64 return avrcpData; 65 } 66 ReadFromParcel(Parcel & parcel)67bool BluetoothAvrcpMpItem::ReadFromParcel(Parcel &parcel) 68 { 69 if (!parcel.ReadUint8(itemType_)) { 70 return false; 71 } 72 if (!parcel.ReadUint16(playerId_)) { 73 return false; 74 } 75 if (!parcel.ReadUint8(majorType_)) { 76 return false; 77 } 78 if (!parcel.ReadUint32(subType_)) { 79 return false; 80 } 81 if (!parcel.ReadUint8(playStatus_)) { 82 return false; 83 } 84 uint32_t size = 0; 85 if (!parcel.ReadUint32(size) || size > AVRCP_READ_FROM_PARCEL_COUNT_MAX) { 86 return false; 87 } 88 for (size_t i = 0; i < size; i++) { 89 uint8_t feature; 90 if (!parcel.ReadUint8(feature)) { 91 return false; 92 } 93 features_.push_back(feature); 94 } 95 if (!parcel.ReadString(name_)) { 96 return false; 97 } 98 return true; 99 } 100 101 } // namespace Bluetooth 102 } // namespace OHOS 103