1 /*
2  * Copyright 2023 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 "list_player_application_setting_attributes.h"
18 
19 namespace bluetooth {
20 namespace avrcp {
21 
22 std::unique_ptr<ListPlayerApplicationSettingAttributesResponseBuilder>
MakeBuilder(std::vector<PlayerAttribute> attributes)23 ListPlayerApplicationSettingAttributesResponseBuilder::MakeBuilder(
24         std::vector<PlayerAttribute> attributes) {
25   std::unique_ptr<ListPlayerApplicationSettingAttributesResponseBuilder> builder(
26           new ListPlayerApplicationSettingAttributesResponseBuilder(std::move(attributes)));
27 
28   return builder;
29 }
30 
size() const31 size_t ListPlayerApplicationSettingAttributesResponseBuilder::size() const {
32   size_t len = VendorPacket::kMinSize();
33   len += sizeof(uint8_t);                       // Number of attributes size
34   len += attributes_.size() * sizeof(uint8_t);  // Attributes size
35   return len;
36 }
37 
Serialize(const std::shared_ptr<::bluetooth::Packet> & pkt)38 bool ListPlayerApplicationSettingAttributesResponseBuilder::Serialize(
39         const std::shared_ptr<::bluetooth::Packet>& pkt) {
40   ReserveSpace(pkt, size());
41 
42   PacketBuilder::PushHeader(pkt);
43 
44   VendorPacketBuilder::PushHeader(pkt, size() - VendorPacket::kMinSize());
45 
46   AddPayloadOctets1(pkt, static_cast<uint8_t>(attributes_.size()));
47   for (auto attribute : attributes_) {
48     AddPayloadOctets1(pkt, static_cast<uint8_t>(attribute));
49   }
50 
51   return true;
52 }
53 
54 }  // namespace avrcp
55 }  // namespace bluetooth
56