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