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