• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         ((((uint64_t)uuid_[0]) << EIGHT*7) | (((uint64_t)uuid_[1]) << EIGHT*6) | (((uint64_t)uuid_[2]) << EIGHT*5) |
26             (((uint64_t)uuid_[3]) << EIGHT*4) | (((uint64_t)uuid_[4]) << EIGHT*3) | (((uint64_t)uuid_[5]) << EIGHT*2) |
27             (((uint64_t)uuid_[6]) << EIGHT) | uuid_[7]);
28 
29     uint64_t leastSigBits =
30         ((((uint64_t)uuid_[8]) << EIGHT*7) | (((uint64_t)uuid_[9]) << EIGHT*6) | (((uint64_t)uuid_[10]) << EIGHT*5) |
31             (((uint64_t)uuid_[11]) << EIGHT*4) | (((uint64_t)uuid_[12]) << EIGHT*3) |
32             (((uint64_t)uuid_[13]) << EIGHT*2) | (((uint64_t)uuid_[14]) << EIGHT) | uuid_[15]);
33 
34     bool ret = parcel.WriteUint64(mostSigBits);
35     if (!ret) {
36         HILOGE("ParcelBtUuid::WriteToParcel write mostSigBits error");
37         return ret;
38     }
39 
40     return parcel.WriteUint64(leastSigBits);
41 }
42 
Unmarshalling(Parcel & parcel)43 BluetoothUuid *BluetoothUuid::Unmarshalling(Parcel &parcel)
44 {
45     uint64_t mostSigBits = parcel.ReadUint64();
46     uint64_t leastSigBits = parcel.ReadUint64();
47     BluetoothUuid *uuid = new BluetoothUuid(bluetooth::Uuid::ConvertFromMostAndLeastBit(mostSigBits, leastSigBits));
48     return uuid;
49 }
50 }  // namespace Bluetooth
51 }  // namespace OHOS