Fix packer: store span_writer by reference, not copy

This commit is contained in:
Ian Gulliver
2026-04-10 23:23:58 +09:00
parent 7264611f99
commit f6d8847bcf
2 changed files with 6 additions and 5 deletions

View File

@@ -164,7 +164,7 @@ inline result<body_info> get_body_info(const uint8_t *p, int size) {
class packer {
private:
span_writer m_buf;
span_writer &m_buf;
template <typename T> void push_big_endian(T n) {
auto p = reinterpret_cast<std::uint8_t *>(&n) + (sizeof(T) - 1);
@@ -178,8 +178,7 @@ private:
}
public:
packer(uint8_t *data, size_t capacity) : m_buf(data, capacity) {}
packer(span_writer buf) : m_buf(buf) {}
packer(span_writer &buf) : m_buf(buf) {}
packer(const packer &) = delete;
packer &operator=(const packer &) = delete;
@@ -409,7 +408,8 @@ public:
requires requires(const T &v) { { T::ext_id } -> std::convertible_to<int8_t>; v.as_tuple(); }
pack_result pack(const T &v) {
uint8_t ext_buf[256];
packer inner(ext_buf, sizeof(ext_buf));
span_writer ext_writer(ext_buf, sizeof(ext_buf));
packer inner(ext_writer);
auto r = inner.pack(v.as_tuple());
if (!r) return r;
return pack_ext(T::ext_id, inner.get_payload());