Zero-copy ethernet TX: encode directly into prepend_buffer, add info/test skills

This commit is contained in:
Ian Gulliver
2026-04-12 07:50:20 +09:00
parent 846d6bb201
commit 761b740c10
6 changed files with 40 additions and 12 deletions

View File

@@ -6,17 +6,17 @@
#include <span>
#include "wire.h"
#include "timer_queue.h"
#include "net.h"
struct responder {
uint32_t message_id;
std::function<void(std::span<const uint8_t>)> send;
send_fn send;
template <typename T>
void respond(const T& msg) const {
uint8_t buf[1024];
span_writer out(buf, sizeof(buf));
auto r = encode_response_into(out, message_id, msg);
if (r) send({buf, *r});
send([&](span_writer& out) {
return encode_response_into(out, message_id, msg);
});
}
};

View File

@@ -13,8 +13,11 @@ struct net_state {
ipv4::ip4_addr ip;
};
using encode_fn = std::function<msgpack::result<size_t>(span_writer&)>;
using send_fn = std::function<void(encode_fn)>;
using net_handler = std::function<void(std::span<const uint8_t> payload,
std::function<void(std::span<const uint8_t>)> send)>;
send_fn send)>;
using net_frame_callback = std::function<bool(std::span<const uint8_t> frame)>;