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 "parcel_bt_uuid.h" 20 #include "bluetooth_log.h" 21 22 namespace OHOS { 23 namespace Bluetooth { WriteToParcel(MessageParcel & parcel,bluetooth::Uuid & uuid)24bool ParcelBtUuid::WriteToParcel(MessageParcel &parcel, bluetooth::Uuid &uuid) 25 { 26 bluetooth::Uuid::UUID128Bit uuid128 = uuid.ConvertTo128Bits(); 27 28 uint64_t mostSigBits = 29 (static_cast<uint64_t>(uuid128[0]) << 56) | (static_cast<uint64_t>(uuid128[1]) << 48) | 30 (static_cast<uint64_t>(uuid128[2]) << 40) | (static_cast<uint64_t>(uuid128[3]) << 32) | 31 (static_cast<uint64_t>(uuid128[4]) << 24) | (static_cast<uint64_t>(uuid128[5]) << 16) | 32 (static_cast<uint64_t>(uuid128[6]) << 8) | static_cast<uint64_t>(uuid128[7]); 33 34 uint64_t leastSigBits = 35 (static_cast<uint64_t>(uuid128[8]) <<56) | (static_cast<uint64_t>(uuid128[9]) << 48) | 36 (static_cast<uint64_t>(uuid128[10]) << 40) | (static_cast<uint64_t>(uuid128[11]) << 32) | 37 (static_cast<uint64_t>(uuid128[12]) << 24) | (static_cast<uint64_t>(uuid128[13]) << 16) | 38 (static_cast<uint64_t>(uuid128[14]) << 8) | static_cast<uint64_t>(uuid128[15]); 39 40 bool ret = parcel.WriteUint64(mostSigBits); 41 if (!ret) { 42 HILOGE("ParcelBtUuid::WriteToParcel write mostSigBits error"); 43 return ret; 44 } 45 46 return parcel.WriteUint64(leastSigBits); 47 } 48 ReadFromParcel(MessageParcel & parcel)49bluetooth::Uuid ParcelBtUuid::ReadFromParcel(MessageParcel &parcel) 50 { 51 uint64_t mostSigBits = parcel.ReadUint64(); 52 uint64_t leastSigBits = parcel.ReadUint64(); 53 54 return bluetooth::Uuid::ConvertFromMostAndLeastBit(mostSigBits, leastSigBits); 55 } 56 } // namespace Bluetooth 57 } // namespace OHOS