Skip to content

Commit 82c0b9b

Browse files
committed
added allocator to rpc data
1 parent 9c91376 commit 82c0b9b

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/framework/audio/common/rpc/rpcpacker.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -750,19 +750,23 @@ class RpcAllocator
750750
{
751751
std::lock_guard<std::mutex> lock(m_mutex);
752752

753+
LOGDA() << "m_currentPos: " << m_currentPos;
753754
if (m_currentPos + n > m_pool.size()) {
754-
size_type newSize = std::max(m_pool.size() * 2, n);
755+
size_type newSize = std::max(m_pool.size() * 2, m_pool.size() + n);
755756
m_pool.resize(newSize);
756757
}
757758

758759
pointer ptr = reinterpret_cast<pointer>(&m_pool[m_currentPos]);
759760
m_currentPos += n;
761+
LOGDA() << "m_currentPos += n: " << m_currentPos;
760762
return ptr;
761763
}
762764

763765
void deallocate(pointer, size_type n)
764766
{
767+
LOGDA() << "m_currentPos: " << m_currentPos;
765768
m_currentPos -= n;
769+
LOGDA() << "m_currentPos -= n: " << m_currentPos;
766770
}
767771
};
768772

@@ -774,10 +778,10 @@ class RpcPacker
774778
template<class ... Types>
775779
static ByteArray pack(const Options& opt, const Types&... args)
776780
{
777-
//RpcAllocator<uint8_t> allocator;
778-
//std::vector<uint8_t, RpcAllocator<uint8_t>> data(allocator);
779-
std::vector<uint8_t> data;
780-
data.reserve(opt.rezerveSize);
781+
RpcAllocator<uint8_t> allocator;
782+
std::vector<uint8_t, RpcAllocator<uint8_t>> data(allocator);
783+
//std::vector<uint8_t> data;
784+
//data.reserve(opt.rezerveSize);
781785
msgpack::pack_to_data(data, args ...);
782786
// return ByteArray::fromRawData(&data[0], data.size());
783787
return ByteArray(&data[0], data.size());

src/framework/audio/tests/rpcpacker_tests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ static constexpr void KNOWN_FIELDS(const T&, const Fields&...)
5151
static_assert(sizeof(T) == sum_sizeof<Fields...>());
5252
}
5353

54+
TEST_F(Audio_RpcPackerTests, Alloc)
55+
{
56+
// int val1_1 = 10;
57+
std::string val1_2 = "he";
58+
59+
ByteArray data = rpc::RpcPacker::pack(val1_2);
60+
61+
//int val2_1 = 0;
62+
std::string val2_2;
63+
bool ok = rpc::RpcPacker::unpack(data, val2_2);
64+
65+
EXPECT_TRUE(ok);
66+
// EXPECT_TRUE(val1_1 == val2_1);
67+
EXPECT_TRUE(val1_2 == val2_2);
68+
}
69+
5470
TEST_F(Audio_RpcPackerTests, AudioResourceMeta)
5571
{
5672
AudioResourceMeta origin;

0 commit comments

Comments
 (0)