#include "log_gate.hpp" #include #include #include #include #include using namespace burstlog; using U = std::uint64_t; namespace { void number(U value) { std::cout << ' ' << value; } void gate_fields(const Gate& g) { for (U v : Snapshot{g.ready,g.start,g.last,g.interval,g.burst,g.used, g.pending,g.requests,g.emitted,g.suppressed,g.closed,g.reported}) number(v); } void result_fields(const Result& r) { number(r.allowed); number(r.blocked); number(r.flushed); number(r.windows); } void command_fields(const Command& c) { number(static_cast(c.kind)); number(c.object); number(c.time); number(c.config.interval); number(c.config.burst); number(c.count); } std::string hex(const std::string& s) { if (s.empty()) return "-"; const char* digits = "0123456789abcdef"; std::string r; for (unsigned char c : s) { r += digits[c >> 4]; r += digits[c & 15]; } return r; } std::string unhex(const std::string& s) { if (s == "-") return {}; std::string r; for (std::size_t i=0;i(std::stoul(s.substr(i,2),nullptr,16))); return r; } } int main() { std::array gates{}; std::string line; while (std::getline(std::cin,line)) { std::istringstream in(line); char tag; in >> tag; if (tag == 'H') { U now,deadline,interval,burst,a,b; in >> now >> deadline >> interval >> burst >> a >> b; Config c{interval,burst}; std::cout << "H"; number(valid_time(now)); number(window_due(now,deadline)); number(valid_config(c)); number(saturating_add(a,b)); number(c.interval); number(c.burst); } else if (tag == 'D') { U limit,seed,mask; std::string encoded; in >> limit >> seed >> mask >> encoded; auto content = unhex(encoded); std::string storage = std::string("\xa5" "9:",3) + content + std::string("7Z\0q",4); std::string_view text(storage.data()+3,content.size()); U value=seed; int rc=parse_decimal(text,limit,mask ? nullptr : &value); std::cout << "D " << rc; number(value); std::cout << ' ' << hex(storage); } else if (tag == 'P') { U seed,mask; std::string encoded; in >> seed >> mask >> encoded; auto content=unhex(encoded); std::string storage = std::string("\xa5" "9:",3) + content + std::string("7Z\0q",4); std::string_view text(storage.data()+3,content.size()); Command c{static_cast(seed),seed+1,seed+2,{seed+3,seed+4},seed+5}; int rc=parse_command(text,mask ? nullptr : &c); std::cout << "P " << rc; command_fields(c); std::cout << ' ' << hex(storage); } else if (tag == 'F') { U mode,seed; in >> mode >> seed; Snapshot s{}; for (std::size_t i=0;i::max() : seed+i; Result r{s[0],s[1],s[2],s[3]}; const auto text=mode ? result_json(r) : snapshot_json(s); std::cout << "F " << hex(text); for (auto value:s) number(value); result_fields(r); } else if (tag == 'R') { U mode,action,object,now,interval,burst,count,seed,mask; in >> mode >> action >> object >> now >> interval >> burst >> count >> seed >> mask; Command c{static_cast(action),object,now,{interval,burst},count}; Config config{interval,burst}; Result result{seed,seed+1,seed+2,seed+3}; Snapshot snapshot{}; for (std::size_t i=0;i