|
26 | 26 | #include "global/serialization/msgpack_forward.h"
|
27 | 27 | #include "../../audiotypes.h"
|
28 | 28 |
|
| 29 | +#include "log.h" |
| 30 | + |
29 | 31 | void pack_custom(muse::msgpack::Packer& p, const muse::audio::PlaybackStatus& value);
|
30 | 32 | void unpack_custom(muse::msgpack::UnPacker& p, muse::audio::PlaybackStatus& value);
|
31 | 33 |
|
@@ -590,19 +592,32 @@ class RpcPacker
|
590 | 592 | template<class ... Types>
|
591 | 593 | static ByteArray pack(const Options& opt, const Types&... args)
|
592 | 594 | {
|
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()); |
594 | 606 | }
|
595 | 607 |
|
596 | 608 | template<class ... Types>
|
597 | 609 | static ByteArray pack(const Types&... args)
|
598 | 610 | {
|
599 |
| - return msgpack::pack(args ...); |
| 611 | + return RpcPacker::pack(Options {}, args ...); |
600 | 612 | }
|
601 | 613 |
|
602 | 614 | template<class ... Types>
|
603 | 615 | static bool unpack(const ByteArray& data, Types&... args)
|
604 | 616 | {
|
605 | 617 | return msgpack::unpack(data, args ...);
|
606 | 618 | }
|
| 619 | + |
| 620 | + static constexpr size_t DEFAULT_CAPACITY = 1024 * 200; |
| 621 | + static inline std::vector<uint8_t> buffer = {}; |
607 | 622 | };
|
608 | 623 | }
|
0 commit comments