Zero-copy TX: span_writer packer, static buffers, no vector returns
This commit is contained in:
@@ -2,10 +2,9 @@
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#include "wire.h"
|
||||
|
||||
using handler_fn = std::vector<std::vector<uint8_t>> (*)(uint32_t message_id, std::span<const uint8_t> payload);
|
||||
using handler_fn = size_t (*)(uint32_t message_id, std::span<const uint8_t> payload, span_writer &out);
|
||||
|
||||
struct handler_entry {
|
||||
int8_t type_id;
|
||||
@@ -13,16 +12,16 @@ struct handler_entry {
|
||||
};
|
||||
|
||||
template <typename Req, auto Fn>
|
||||
std::vector<std::vector<uint8_t>> typed_handler(uint32_t message_id, std::span<const uint8_t> payload) {
|
||||
size_t typed_handler(uint32_t message_id, std::span<const uint8_t> payload, span_writer &out) {
|
||||
msgpack::parser p(payload.data(), static_cast<int>(payload.size()));
|
||||
Req req;
|
||||
auto tup = req.as_tuple();
|
||||
auto r = msgpack::unpack(p, tup);
|
||||
if (!r) {
|
||||
return {encode_response(message_id, DeviceError{1, "decode request ext_id=" +
|
||||
std::to_string(Req::ext_id) + ": msgpack error " + std::to_string(static_cast<int>(r.error()))})};
|
||||
return encode_response_into(out, message_id, DeviceError{1, "decode request ext_id=" +
|
||||
std::to_string(Req::ext_id) + ": msgpack error " + std::to_string(static_cast<int>(r.error()))});
|
||||
}
|
||||
return Fn(message_id, req);
|
||||
return Fn(message_id, req, out);
|
||||
}
|
||||
|
||||
void dispatch_init();
|
||||
|
||||
Reference in New Issue
Block a user