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