// Copyright (C) 2021-2022 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 3 of the License, or (at your option) // any later version. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for // more details. // // You should have received a copy of the GNU General Public License along with // this program; if not, write to the Free Software Foundation, Inc., 51 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #pragma once #include #include #include #include #include #include #include #include // Cache entry format // ================== // // Integers are big-endian. // // ::=
//
::= // // // ::= uint16_t (0xccac) // ::= uint8_t // ::= | // ::= 0 (uint8_t) // ::= 1 (uint8_t) // ::= 0/1 (uint8_t) ; whether suitable for remote storage // ::= | // ::= 0 (uint8_t) // ::= 1 (uint8_t) // ::= int8_t // ::= uint64_t (Unix epoch time when entry was created) // ::= string length (uint8_t) + string data // ::= string length (uint8_t) + string data // ::= uint64_t ; = size of entry in uncompressed form // ::= depends on entry_type; potentially compressed // ::= // ::= uint64_t ; XXH3-128 (high bits) of
+ // ::= uint64_t ; XXH3-128 (low bits) of
+ class Config; namespace core { const uint16_t k_ccache_magic = 0xccac; class CacheEntry { public: static const uint8_t k_format_version; constexpr static uint8_t default_compression_level = 1; class Header { public: Header(const Config& config, CacheEntryType entry_type); explicit Header(nonstd::span data); explicit Header(const std::string& path); std::string inspect() const; uint16_t magic; uint8_t entry_format_version; CacheEntryType entry_type; CompressionType compression_type; int8_t compression_level; bool self_contained; uint64_t creation_time; std::string ccache_version; std::string namespace_; uint64_t entry_size; size_t serialized_size() const; void serialize(util::Bytes& output) const; uint32_t uncompressed_payload_size() const; private: void parse(nonstd::span data); }; explicit CacheEntry(nonstd::span data); void verify_checksum() const; const Header& header() const; // Return uncompressed payload. nonstd::span payload() const; static util::Bytes serialize(const Header& header, Serializer& payload_serializer); static util::Bytes serialize(const Header& header, nonstd::span payload); private: Header m_header; nonstd::span m_payload; // Potentially compressed util::Bytes m_checksum; mutable util::Bytes m_uncompressed_payload; static util::Bytes do_serialize(const Header& header, size_t serialized_payload_size, std::function serialize_payload); }; } // namespace core