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