// DragonX Wallet - ImGui Edition // Shared absolute-offset output ring helpers (daemon debug.log feed, xmrig console feed). #pragma once #include #include namespace dragonx { namespace daemon { // getOutputSince() over a buffer holding the LAST buffer.size() of `total` bytes ever appended. inline std::string outputWindowSince(const std::string& buffer, std::size_t total, std::size_t& offset) { const std::size_t base = total - buffer.size(); // absolute position of buffer[0] if (offset < base) offset = base; // trimmed before read: resume at what's left if (offset >= total) { offset = total; return {}; } std::string result = buffer.substr(offset - base); offset = total; return result; } // Append `n` bytes, advance absolute `total`, and trim to ~cap at a newline once size exceeds 1.25x cap. // The `nl < size-1` guard keeps a lone trailing newline from erasing the whole buffer. inline void appendBounded(std::string& buffer, std::size_t& total, const char* data, std::size_t n, std::size_t cap) { buffer.append(data, n); total += n; if (buffer.size() > cap + cap / 4) { const std::size_t trim_to = buffer.size() - cap; const std::size_t nl = buffer.find('\n', trim_to); if (nl != std::string::npos && nl < buffer.size() - 1) buffer.erase(0, nl + 1); else buffer.erase(0, trim_to); } } } // namespace daemon } // namespace dragonx