1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "discovery/device/data_parser.h"
18 
19 #include "hci/hci_packets.h"
20 #include "packet/iterator.h"
21 
22 using namespace bluetooth;
23 
24 using namespace bluetooth::hci;
25 using namespace bluetooth::packet;
26 
27 namespace bluetooth::discovery::device {
28 
DataParser(const std::vector<uint8_t> & data)29 DataParser::DataParser(const std::vector<uint8_t>& data) {
30   auto it = Iterator<kLittleEndian>(std::make_shared<std::vector<uint8_t>>(data));
31 
32   while (it.NumBytesRemaining()) {
33     GapData gap_data;
34     it = GapData::Parse(&gap_data, it);
35     gap_data_.push_back(gap_data);
36   }
37 }
38 
GetNumGapData() const39 size_t DataParser::GetNumGapData() const {
40   return gap_data_.size();
41 }
42 
GetData() const43 std::vector<hci::GapData> DataParser::GetData() const {
44   return std::vector<hci::GapData>(gap_data_);
45 }
46 
GetDataTypes() const47 std::vector<hci::GapDataType> DataParser::GetDataTypes() const {
48   std::vector<hci::GapDataType> types;
49   for (const auto& gap_data : gap_data_) types.push_back(gap_data.data_type_);
50   return types;
51 }
52 
53 }  // namespace bluetooth::discovery::device
54