Skip to content

Commit adbe580

Browse files
committed
added persistence buffer to audio rpc packer
1 parent 952da6a commit adbe580

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "global/serialization/msgpack_forward.h"
2727
#include "../../audiotypes.h"
2828

29+
#include "log.h"
30+
2931
void pack_custom(muse::msgpack::Packer& p, const muse::audio::PlaybackStatus& value);
3032
void unpack_custom(muse::msgpack::UnPacker& p, muse::audio::PlaybackStatus& value);
3133

@@ -590,19 +592,32 @@ class RpcPacker
590592
template<class ... Types>
591593
static ByteArray pack(const Options& opt, const Types&... args)
592594
{
593-
return msgpack::pack(opt, args ...);
595+
// clear but keep capacity
596+
buffer.clear();
597+
// makes sense if the reserve is greater than the current capacity
598+
buffer.reserve(std::max(opt.rezerveSize, DEFAULT_CAPACITY));
599+
msgpack::pack(buffer, args ...);
600+
601+
IF_ASSERT_FAILED(buffer.size() > 0) {
602+
return ByteArray();
603+
}
604+
605+
return ByteArray(&buffer[0], buffer.size());
594606
}
595607

596608
template<class ... Types>
597609
static ByteArray pack(const Types&... args)
598610
{
599-
return msgpack::pack(args ...);
611+
return RpcPacker::pack(Options {}, args ...);
600612
}
601613

602614
template<class ... Types>
603615
static bool unpack(const ByteArray& data, Types&... args)
604616
{
605617
return msgpack::unpack(data, args ...);
606618
}
619+
620+
static constexpr size_t DEFAULT_CAPACITY = 1024 * 200;
621+
static inline std::vector<uint8_t> buffer = {};
607622
};
608623
}

0 commit comments

Comments
 (0)