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 #ifndef LOG_TAG 16 #define LOG_TAG "bt_ipc_parcel_uuid" 17 #endif 18 19 #include "bluetooth_bt_uuid.h" 20 #include "bluetooth_log.h" 21 22 namespace OHOS { 23 namespace Bluetooth { 24 #define EIGHT 8 Marshalling(Parcel & parcel) const25bool BluetoothUuid::Marshalling(Parcel &parcel) const 26 { 27 uint64_t mostSigBits = 28 (((static_cast<uint64_t>(uuid_[0])) << EIGHT * 7) | ((static_cast<uint64_t>(uuid_[1])) << EIGHT * 6) | 29 ((static_cast<uint64_t>(uuid_[2])) << EIGHT * 5) | ((static_cast<uint64_t>(uuid_[3])) << EIGHT * 4) | 30 ((static_cast<uint64_t>(uuid_[4])) << EIGHT * 3) | ((static_cast<uint64_t>(uuid_[5])) << EIGHT * 2) | 31 ((static_cast<uint64_t>(uuid_[6])) << EIGHT) | uuid_[7]); 32 33 uint64_t leastSigBits = 34 (((static_cast<uint64_t>(uuid_[8])) << EIGHT * 7) | ((static_cast<uint64_t>(uuid_[9])) << EIGHT * 6) | 35 ((static_cast<uint64_t>(uuid_[10])) << EIGHT * 5) | ((static_cast<uint64_t>(uuid_[11])) << EIGHT * 4) | 36 ((static_cast<uint64_t>(uuid_[12])) << EIGHT * 3) | ((static_cast<uint64_t>(uuid_[13])) << EIGHT * 2) | 37 ((static_cast<uint64_t>(uuid_[14])) << EIGHT) | uuid_[15]); 38 39 bool ret = parcel.WriteUint64(mostSigBits); 40 if (!ret) { 41 HILOGE("ParcelBtUuid::WriteToParcel write mostSigBits error"); 42 return ret; 43 } 44 45 return parcel.WriteUint64(leastSigBits); 46 } 47 Unmarshalling(Parcel & parcel)48BluetoothUuid *BluetoothUuid::Unmarshalling(Parcel &parcel) 49 { 50 uint64_t mostSigBits = parcel.ReadUint64(); 51 uint64_t leastSigBits = parcel.ReadUint64(); 52 BluetoothUuid *uuid = new BluetoothUuid(bluetooth::Uuid::ConvertFromMostAndLeastBit(mostSigBits, leastSigBits)); 53 return uuid; 54 } 55 } // namespace Bluetooth 56 } // namespace OHOS