3#include "pixelbullet/filesystem/native_path.h"
11namespace pixelbullet::mesh_binary_internal
13[[nodiscard]]
inline bool AddBytes(std::uint64_t& total,
const std::uint64_t bytes)
noexcept
15 if (bytes > std::numeric_limits<std::uint64_t>::max() - total)
23[[nodiscard]]
inline bool MultiplyBytes(
const std::uint64_t count,
const std::uint64_t stride, std::uint64_t& bytes)
noexcept
25 if (count != 0u && stride > std::numeric_limits<std::uint64_t>::max() / count)
29 bytes = count * stride;
33[[nodiscard]]
inline bool AddRepeatedBytes(std::uint64_t& total,
const std::uint64_t count,
const std::uint64_t stride)
noexcept
35 std::uint64_t bytes = 0u;
36 return MultiplyBytes(count, stride, bytes) && AddBytes(total, bytes);
39[[nodiscard]]
inline bool TryGetFileSize(
const std::filesystem::path& path, std::uint64_t& size, std::string* error_message)
41 std::error_code error_code;
42 const std::uintmax_t raw_size = std::filesystem::file_size(filesystem::to_native_file_io_path(path), error_code);
45 if (error_message !=
nullptr)
47 *error_message = error_code.message();
52 if (raw_size >
static_cast<std::uintmax_t
>(std::numeric_limits<std::uint64_t>::max()))
54 if (error_message !=
nullptr)
56 *error_message =
"file size exceeds supported range";
61 size =
static_cast<std::uint64_t
>(raw_size);
65[[nodiscard]]
inline bool FitsFileSize(
const std::uint64_t required_size,
const std::uint64_t file_size)
noexcept
67 return required_size <= file_size;