#pragma once #include class Parser { private: const char *buf; size_t remaining; public: inline Parser(const char *buf, size_t len) : buf(buf), remaining(len) { } class EndOfInput {}; inline bool end() const { return this->remaining == 0; } inline size_t available() const { return this->remaining; } template T get() { if (this->remaining < sizeof(T)) { throw EndOfInput(); } else { T x = *(T *) this->buf; this->buf += sizeof(T); this->remaining -= sizeof(T); return x; } } };