Zero-copy TX: span_writer packer, static buffers, no vector returns

This commit is contained in:
Ian Gulliver
2026-04-10 22:18:44 +09:00
parent 94895fd2fe
commit e2a5d97dae
10 changed files with 173 additions and 133 deletions

View File

@@ -29,8 +29,10 @@ static ResponseTest test_discovery() {
ResponseTest resp;
resp.pass = true;
auto req = encode_request(0, RequestInfo{});
auto send_result = w6300::send(test_socket, std::span<const uint8_t>{req});
uint8_t req_buf[256];
span_writer req_out(req_buf, sizeof(req_buf));
size_t req_len = encode_request_into(req_out, 0, RequestInfo{});
auto send_result = w6300::send(test_socket, std::span<const uint8_t>{req_buf, req_len});
if (!send_result) {
resp.pass = false;
resp.messages.push_back("send: error " + std::to_string(static_cast<int>(send_result.error())));
@@ -95,13 +97,11 @@ static const std::unordered_map<std::string_view, test_fn> tests = {
{"discovery", test_discovery},
};
static std::vector<std::vector<uint8_t>> handle_test(uint32_t message_id, const RequestTest& req) {
static size_t handle_test(uint32_t message_id, const RequestTest& req, span_writer &out) {
auto it = tests.find(req.name);
if (it == tests.end()) {
return {encode_response(message_id, ResponseTest{false, {"unknown test: " + req.name}})};
}
return {encode_response(message_id, it->second())};
if (it == tests.end())
return encode_response_into(out, message_id, ResponseTest{false, {"unknown test: " + req.name}});
return encode_response_into(out, message_id, it->second());
}
static constexpr handler_entry handlers[] = {