#include "parselink/msgpack/token.h" // #include "parselink/proto/message.h" #include #include #include #include #include #include #include using namespace std::chrono_literals; struct any { template operator T() {} }; auto read_file(char const* filename) { std::vector data; auto fd = open(filename, O_RDONLY); if (!fd) { fmt::print("Could not open {}: {}\n", filename, strerror(errno)); return data; } auto size = lseek(fd, 0, SEEK_END); data.resize(size); lseek(fd, 0, SEEK_SET); fmt::print("Reading {} bytes from {}\n", size, filename); read(fd, data.data(), data.size()); close(fd); return data; } int main(int argc, char** argv) { std::array buf; auto data = read_file(argc < 2 ? "output.bin" : argv[1]); msgpack::token_reader reader(data); auto before = std::chrono::steady_clock::now(); auto test = reader.read_some(buf); auto after = std::chrono::steady_clock::now(); test.map([&](auto sp) { fmt::print("Read {} tokens\n", sp.size()); for (auto token : sp) { fmt::print("token type: {} value: ", magic_enum::enum_name(token.type())); switch (token.type()) { case msgpack::format::type::unsigned_int: fmt::print( "{}", *(token.template get())); break; case msgpack::format::type::signed_int: fmt::print("{}", *(token.template get())); break; case msgpack::format::type::boolean: fmt::print("{}", *(token.template get())); break; case msgpack::format::type::string: fmt::print("{}", *(token.template get())); break; case msgpack::format::type::binary: fmt::print( "{}", *(token.template get< std::span>())); break; case msgpack::format::type::map: fmt::print("map ({} entries)", token.template get()->count); break; case msgpack::format::type::array: fmt::print("array ({} entries)", token.template get() ->count); break; case msgpack::format::type::nil: fmt::print("(nil)"); break; case msgpack::format::type::invalid: fmt::print("(invalid)"); break; } fmt::print("\n"); } }).map_error([&](auto err) { fmt::print("Failed to read tokens: {}\n", (int)err); }); fmt::print("Took {} us\n", (after - before) / 1us); }