#pragma once #include "net.h" #include #include #include #include namespace vn::wire { constexpr std::size_t MAX_FRAME = 16u * 1024u * 1024u; enum Kind : std::uint8_t { HELLO = 1, HELLO_OK = 2, AUTH = 3, AUTH_OK = 4, WHOAMI = 5, WHOAMI_OK = 6, LIST_REFS = 7, REFS = 8, NEGOTIATE = 9, NEGOTIATE_OK = 10, FETCH_SKELETON = 11, GET_CHUNKS = 12, HAVE_QUERY = 13, HAVE_BITMAP = 14, PUT_RECORDS = 15, UPDATE_REFS = 16, UPDATE_REFS_OK = 17, RECORDS = 18, END = 19, ERROR = 20, }; enum ErrorCode : std::uint8_t { ERR_UNSUPPORTED_VERSION = 1, ERR_BAD_FRAME = 2, ERR_NOT_FOUND = 3, ERR_HASH_MISMATCH = 4, ERR_NON_CANONICAL = 5, ERR_MISSING_CLOSURE = 6, ERR_REF_CONFLICT = 7, ERR_REJECTED = 8, ERR_INTERNAL = 9, ERR_UNAUTHENTICATED = 10, ERR_FORBIDDEN = 11, ERR_AUTH_FAILED = 12, ERR_QUOTA = 13, ERR_TOO_LARGE = 14, }; struct Frame { std::uint8_t kind = 0; std::uint32_t request_id = 0; std::vector payload; }; std::optional read_frame(net::Stream &stream); bool write_frame(net::Stream &stream, std::uint8_t kind, std::uint32_t request_id, Bytes payload); bool write_simple(net::Stream &stream, std::uint8_t kind, std::uint32_t request_id); bool write_error(net::Stream &stream, std::uint32_t request_id, std::uint8_t code, std::string_view message); std::uint8_t read_error(Bytes payload); std::string error_message(Bytes payload); std::string_view error_code_name(std::uint8_t code); // Encode/decode the record layout shared by packs and RECORDS frames. struct IncomingRecord { Id id{}; std::uint8_t kind = 0; std::vector body; }; std::optional parse_record(Bytes data); std::vector make_record(const Id &id, std::uint8_t kind, Bytes body); } // namespace vn::wire