17 static const std::uint8_t kFcb[3] = {
'f',
'c',
'b'};
18 if (std::memcmp(b.
data() + 0, kFcb, 3) != 0)
20 if (std::memcmp(b.
data() + 4, kFcb, 3) != 0)
31 "invalid index_node_size: " + std::to_string(
node_size));
38 std::uint64_t n = num_items;
39 std::uint64_t num_nodes = n;
42 num_nodes = checked_add(num_nodes, n,
"rtree num_nodes");
46 return checked_mul(num_nodes,
kNodeItemSize,
"rtree index size");
50 std::uint16_t index_node_size, std::uint64_t attr_index_size) {
53 "illegal header size: " + std::to_string(header_size));
58 l.rtree_begin = l.header_len;
61 l.rtree_size = (index_node_size == 0 || features_count == 0)
64 l.attr_index_begin = checked_add(l.rtree_begin, l.rtree_size,
"attr_index_begin");
65 l.attr_index_size = attr_index_size;
66 l.feature_begin = checked_add(l.attr_index_begin, l.attr_index_size,
"feature_begin");
74 "sections extend past end of file: feature_begin=" + std::to_string(l.
feature_begin) +
75 " total_size=" + std::to_string(total_size));
Every failure the library reports is one of these.
Minimal C++17 stand-in for std::span: a non-owning view over contiguous memory.
std::size_t size() const noexcept
T * data() const noexcept
std::uint64_t checked_mul(std::uint64_t a, std::uint64_t b, const char *what="mul")
std::uint64_t checked_add(std::uint64_t a, std::uint64_t b, const char *what="add")
std::uint64_t ceil_div(std::uint64_t a, std::uint64_t b)
ceil(a / b) without the (a + b - 1) overflow hazard.
std::uint64_t rtree_index_size(std::uint64_t num_items, std::uint16_t node_size)
Mirrors PackedRTree::index_size (packed_rtree/mod.rs:879-898).
constexpr std::size_t kNodeItemSize
constexpr std::size_t kHeaderMaxBufferSize
constexpr std::size_t kHeaderSizeSize
FileLayout compute_layout(std::uint32_t header_size, std::uint64_t features_count, std::uint16_t index_node_size, std::uint64_t attr_index_size)
Throws fcb::Error{IllegalHeaderSize} when header_size is out of range or any size arithmetic overflow...
constexpr std::uint8_t kVersion
void validate_layout_against_size(const FileLayout &l, std::uint64_t total_size)
Throws unless the computed sections fit inside the resource.
bool check_magic_bytes(bytes_view b)
Mirrors fcb_core::check_magic_bytes (src/rust/fcb_core/src/lib.rs:56-58).
constexpr std::size_t kMagicBytesSize
Byte offsets of each section.
std::uint64_t feature_begin