lib/tldr/src/formats/elf/layout/merge.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const section = @import("section.zig");
 2 
 3 const SectionContribution = section.SectionContribution;
 4 
 5 pub const MergePieceLayout = struct {
 6     input_offset: u64 = 0,
 7     size: u64 = 0,
 8     contribution: SectionContribution = .{},
 9     output_intra_offset: u64 = 0,
10 };
11 
12 pub const MergeSectionLayout = struct {
13     pieces: []MergePieceLayout = &.{},
14     fixed_piece_size: u64 = 0,
15 
16     pub fn deinit(self: *MergeSectionLayout, allocator: anytype) void {
17         if (self.pieces.len != 0) allocator.free(self.pieces);
18     }
19 
20     pub fn isPresent(self: MergeSectionLayout) bool {
21         return self.pieces.len != 0;
22     }
23 };
24 
25 pub fn sectionAt(sections: []const MergeSectionLayout, section_index: usize) ?MergeSectionLayout {
26     if (section_index >= sections.len) return null;
27     const merge_section = sections[section_index];
28     if (!merge_section.isPresent()) return null;
29     return merge_section;
30 }