• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 #pragma once
18 
19 #include <cstdint>
20 #include <memory>
21 
22 #include "base/logging.h"
23 
24 #include "include/le_advertisement.h"
25 #include "packets/packet_builder.h"
26 
27 namespace test_vendor_lib {
28 namespace packets {
29 
30 class LeAdvertisementBuilder : public PacketBuilder<true>, public LeAdvertisement {
31  public:
32   virtual ~LeAdvertisementBuilder() = default;
33 
Create(AddressType address_type,AdvertisementType advertisement_type,const std::vector<uint8_t> & advertisement)34   static std::unique_ptr<LeAdvertisementBuilder> Create(AddressType address_type, AdvertisementType advertisement_type,
35                                                         const std::vector<uint8_t>& advertisement) {
36     return std::unique_ptr<LeAdvertisementBuilder>(
37         new LeAdvertisementBuilder(address_type, advertisement_type, advertisement));
38   }
39 
size()40   virtual size_t size() const override {
41     return sizeof(address_type_) + sizeof(advertisement_type_) + advertisement_.size();
42   }
43 
44  protected:
Serialize(std::back_insert_iterator<std::vector<uint8_t>> it)45   virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
46     insert(static_cast<uint8_t>(address_type_), it);
47     insert(static_cast<uint8_t>(advertisement_type_), it);
48     insert_vector(advertisement_, it);
49   }
50 
51  private:
52   LeAdvertisementBuilder() = delete;
LeAdvertisementBuilder(AddressType address_type,AdvertisementType advertisement_type,const std::vector<uint8_t> & advertisement)53   explicit LeAdvertisementBuilder(AddressType address_type, AdvertisementType advertisement_type,
54                                   const std::vector<uint8_t>& advertisement)
55       : address_type_(address_type), advertisement_type_(advertisement_type), advertisement_(advertisement) {}
56   AddressType address_type_;
57   AdvertisementType advertisement_type_;
58   std::vector<uint8_t> advertisement_;
59 };
60 
61 }  // namespace packets
62 }  // namespace test_vendor_lib
63