Loading system/gd/hci/hci_layer_test.cc +4 −4 Original line number Diff line number Diff line Loading @@ -747,7 +747,7 @@ TEST_F(HciTest, createConnectionTest) { PacketBoundaryFlag packet_boundary_flag = PacketBoundaryFlag::FIRST_AUTOMATICALLY_FLUSHABLE; BroadcastFlag broadcast_flag = BroadcastFlag::POINT_TO_POINT; auto acl_payload = std::make_unique<RawBuilder>(); acl_payload->AddAddress(bd_addr); acl_payload->AddOctets(bd_addr.address); acl_payload->AddOctets2(handle); auto incoming_acl_future = upper->GetReceivedAclFuture(); hal->callbacks->aclDataReceived( Loading @@ -768,7 +768,7 @@ TEST_F(HciTest, createConnectionTest) { BroadcastFlag broadcast_flag2 = BroadcastFlag::POINT_TO_POINT; auto acl_payload2 = std::make_unique<RawBuilder>(); acl_payload2->AddOctets2(handle); acl_payload2->AddAddress(bd_addr); acl_payload2->AddOctets(bd_addr.address); auto sent_acl_future = hal->GetSentAclFuture(); upper->SendAclData(AclBuilder::Create(handle, packet_boundary_flag2, broadcast_flag2, std::move(acl_payload2))); Loading @@ -794,7 +794,7 @@ TEST_F(HciTest, receiveMultipleAclPackets) { BroadcastFlag broadcast_flag = BroadcastFlag::POINT_TO_POINT; for (uint16_t i = 0; i < num_packets; i++) { auto acl_payload = std::make_unique<RawBuilder>(); acl_payload->AddAddress(bd_addr); acl_payload->AddOctets(bd_addr.address); acl_payload->AddOctets2(handle); acl_payload->AddOctets2(i); hal->callbacks->aclDataReceived( Loading Loading @@ -832,7 +832,7 @@ TEST_F(HciTest, receiveMultipleAclPackets) { // One last packet to make sure they were all sent. Already got the future. auto acl_payload = std::make_unique<RawBuilder>(); acl_payload->AddAddress(bd_addr); acl_payload->AddOctets(bd_addr.address); acl_payload->AddOctets2(handle); acl_payload->AddOctets2(num_packets); hal->callbacks->aclDataReceived( Loading system/gd/packet/raw_builder.cc +3 −15 Original line number Diff line number Diff line Loading @@ -21,16 +21,13 @@ #include "os/log.h" using bluetooth::hci::Address; using std::vector; namespace bluetooth { namespace packet { RawBuilder::RawBuilder(size_t max_bytes) : max_bytes_(max_bytes) {} RawBuilder::RawBuilder(std::vector<uint8_t> vec) : payload_(std::move(vec)) {} bool RawBuilder::AddOctets(size_t octets, const vector<uint8_t>& bytes) { bool RawBuilder::AddOctets(size_t octets, const std::vector<uint8_t>& bytes) { if (payload_.size() + octets > max_bytes_) return false; if (octets != bytes.size()) return false; Loading @@ -40,12 +37,12 @@ bool RawBuilder::AddOctets(size_t octets, const vector<uint8_t>& bytes) { return true; } bool RawBuilder::AddOctets(const vector<uint8_t>& bytes) { bool RawBuilder::AddOctets(const std::vector<uint8_t>& bytes) { return AddOctets(bytes.size(), bytes); } bool RawBuilder::AddOctets(size_t octets, uint64_t value) { vector<uint8_t> val_vector; std::vector<uint8_t> val_vector; uint64_t v = value; Loading @@ -61,15 +58,6 @@ bool RawBuilder::AddOctets(size_t octets, uint64_t value) { return AddOctets(octets, val_vector); } bool RawBuilder::AddAddress(const Address& address) { if (payload_.size() + Address::kLength > max_bytes_) return false; for (size_t i = 0; i < Address::kLength; i++) { payload_.push_back(address.address[i]); } return true; } bool RawBuilder::AddOctets1(uint8_t value) { return AddOctets(1, value); } Loading system/gd/packet/raw_builder.h +13 −5 Original line number Diff line number Diff line Loading @@ -16,10 +16,10 @@ #pragma once #include <array> #include <cstdint> #include <vector> #include "hci/address.h" #include "packet/bit_inserter.h" #include "packet/packet_builder.h" Loading @@ -37,10 +37,6 @@ class RawBuilder : public PacketBuilder<true> { virtual void Serialize(BitInserter& it) const; // Add |address| to the payload. Return true if: // - the new size of the payload is still <= |max_bytes_| bool AddAddress(const hci::Address& address); // Return true if |num_bytes| can be added to the payload. bool CanAddOctets(size_t num_bytes) const; Loading @@ -49,6 +45,18 @@ class RawBuilder : public PacketBuilder<true> { // - the new size of the payload is still <= |max_bytes_| bool AddOctets(size_t octets, const std::vector<uint8_t>& bytes); // Add |N| bytes to the payload. Return true if: // - the new size of the payload is still <= |max_bytes_| template <std::size_t N> bool AddOctets(const std::array<uint8_t, N>& bytes) { if (payload_.size() + N > max_bytes_) { return false; } payload_.insert(payload_.end(), bytes.begin(), bytes.end()); return true; } bool AddOctets(const std::vector<uint8_t>& bytes); bool AddOctets1(uint8_t value); Loading system/gd/packet/raw_builder_unittest.cc +1 −4 Original line number Diff line number Diff line Loading @@ -20,9 +20,6 @@ #include <forward_list> #include <memory> #include "hci/address.h" using bluetooth::hci::Address; using bluetooth::packet::BitInserter; using std::vector; Loading Loading @@ -51,7 +48,7 @@ TEST(RawBuilderTest, buildCountTest) { count_builder->AddOctets2(0x0d0c); count_builder->AddOctets1(0x0e); count_builder->AddOctets1(0x0f); count_builder->AddAddress(Address({0x10, 0x11, 0x12, 0x13, 0x14, 0x15})); count_builder->AddOctets(std::array<uint8_t, 6>{0x10, 0x11, 0x12, 0x13, 0x14, 0x15}); std::vector<uint8_t> count_subset(count.begin() + 0x16, count.end()); count_builder->AddOctets(count_subset); Loading Loading
system/gd/hci/hci_layer_test.cc +4 −4 Original line number Diff line number Diff line Loading @@ -747,7 +747,7 @@ TEST_F(HciTest, createConnectionTest) { PacketBoundaryFlag packet_boundary_flag = PacketBoundaryFlag::FIRST_AUTOMATICALLY_FLUSHABLE; BroadcastFlag broadcast_flag = BroadcastFlag::POINT_TO_POINT; auto acl_payload = std::make_unique<RawBuilder>(); acl_payload->AddAddress(bd_addr); acl_payload->AddOctets(bd_addr.address); acl_payload->AddOctets2(handle); auto incoming_acl_future = upper->GetReceivedAclFuture(); hal->callbacks->aclDataReceived( Loading @@ -768,7 +768,7 @@ TEST_F(HciTest, createConnectionTest) { BroadcastFlag broadcast_flag2 = BroadcastFlag::POINT_TO_POINT; auto acl_payload2 = std::make_unique<RawBuilder>(); acl_payload2->AddOctets2(handle); acl_payload2->AddAddress(bd_addr); acl_payload2->AddOctets(bd_addr.address); auto sent_acl_future = hal->GetSentAclFuture(); upper->SendAclData(AclBuilder::Create(handle, packet_boundary_flag2, broadcast_flag2, std::move(acl_payload2))); Loading @@ -794,7 +794,7 @@ TEST_F(HciTest, receiveMultipleAclPackets) { BroadcastFlag broadcast_flag = BroadcastFlag::POINT_TO_POINT; for (uint16_t i = 0; i < num_packets; i++) { auto acl_payload = std::make_unique<RawBuilder>(); acl_payload->AddAddress(bd_addr); acl_payload->AddOctets(bd_addr.address); acl_payload->AddOctets2(handle); acl_payload->AddOctets2(i); hal->callbacks->aclDataReceived( Loading Loading @@ -832,7 +832,7 @@ TEST_F(HciTest, receiveMultipleAclPackets) { // One last packet to make sure they were all sent. Already got the future. auto acl_payload = std::make_unique<RawBuilder>(); acl_payload->AddAddress(bd_addr); acl_payload->AddOctets(bd_addr.address); acl_payload->AddOctets2(handle); acl_payload->AddOctets2(num_packets); hal->callbacks->aclDataReceived( Loading
system/gd/packet/raw_builder.cc +3 −15 Original line number Diff line number Diff line Loading @@ -21,16 +21,13 @@ #include "os/log.h" using bluetooth::hci::Address; using std::vector; namespace bluetooth { namespace packet { RawBuilder::RawBuilder(size_t max_bytes) : max_bytes_(max_bytes) {} RawBuilder::RawBuilder(std::vector<uint8_t> vec) : payload_(std::move(vec)) {} bool RawBuilder::AddOctets(size_t octets, const vector<uint8_t>& bytes) { bool RawBuilder::AddOctets(size_t octets, const std::vector<uint8_t>& bytes) { if (payload_.size() + octets > max_bytes_) return false; if (octets != bytes.size()) return false; Loading @@ -40,12 +37,12 @@ bool RawBuilder::AddOctets(size_t octets, const vector<uint8_t>& bytes) { return true; } bool RawBuilder::AddOctets(const vector<uint8_t>& bytes) { bool RawBuilder::AddOctets(const std::vector<uint8_t>& bytes) { return AddOctets(bytes.size(), bytes); } bool RawBuilder::AddOctets(size_t octets, uint64_t value) { vector<uint8_t> val_vector; std::vector<uint8_t> val_vector; uint64_t v = value; Loading @@ -61,15 +58,6 @@ bool RawBuilder::AddOctets(size_t octets, uint64_t value) { return AddOctets(octets, val_vector); } bool RawBuilder::AddAddress(const Address& address) { if (payload_.size() + Address::kLength > max_bytes_) return false; for (size_t i = 0; i < Address::kLength; i++) { payload_.push_back(address.address[i]); } return true; } bool RawBuilder::AddOctets1(uint8_t value) { return AddOctets(1, value); } Loading
system/gd/packet/raw_builder.h +13 −5 Original line number Diff line number Diff line Loading @@ -16,10 +16,10 @@ #pragma once #include <array> #include <cstdint> #include <vector> #include "hci/address.h" #include "packet/bit_inserter.h" #include "packet/packet_builder.h" Loading @@ -37,10 +37,6 @@ class RawBuilder : public PacketBuilder<true> { virtual void Serialize(BitInserter& it) const; // Add |address| to the payload. Return true if: // - the new size of the payload is still <= |max_bytes_| bool AddAddress(const hci::Address& address); // Return true if |num_bytes| can be added to the payload. bool CanAddOctets(size_t num_bytes) const; Loading @@ -49,6 +45,18 @@ class RawBuilder : public PacketBuilder<true> { // - the new size of the payload is still <= |max_bytes_| bool AddOctets(size_t octets, const std::vector<uint8_t>& bytes); // Add |N| bytes to the payload. Return true if: // - the new size of the payload is still <= |max_bytes_| template <std::size_t N> bool AddOctets(const std::array<uint8_t, N>& bytes) { if (payload_.size() + N > max_bytes_) { return false; } payload_.insert(payload_.end(), bytes.begin(), bytes.end()); return true; } bool AddOctets(const std::vector<uint8_t>& bytes); bool AddOctets1(uint8_t value); Loading
system/gd/packet/raw_builder_unittest.cc +1 −4 Original line number Diff line number Diff line Loading @@ -20,9 +20,6 @@ #include <forward_list> #include <memory> #include "hci/address.h" using bluetooth::hci::Address; using bluetooth::packet::BitInserter; using std::vector; Loading Loading @@ -51,7 +48,7 @@ TEST(RawBuilderTest, buildCountTest) { count_builder->AddOctets2(0x0d0c); count_builder->AddOctets1(0x0e); count_builder->AddOctets1(0x0f); count_builder->AddAddress(Address({0x10, 0x11, 0x12, 0x13, 0x14, 0x15})); count_builder->AddOctets(std::array<uint8_t, 6>{0x10, 0x11, 0x12, 0x13, 0x14, 0x15}); std::vector<uint8_t> count_subset(count.begin() + 0x16, count.end()); count_builder->AddOctets(count_subset); Loading