lib/tldr/src/formats/elf/group/record.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const root = @import("../../../root.zig");
 2 const elf = @import("../root.zig");
 3 
 4 const model = root.model;
 5 const ObjectFile = elf.parser.ObjectFile;
 6 const SectionHeader = elf.format.SectionHeader;
 7 const group_word_size = elf.format.group_word_size;
 8 const readU32 = elf.format.readU32;
 9 const sectionBytes = elf.format.sectionBytes;
10 
11 pub const Members = struct {
12     group_bytes: []const u8,
13     index: usize = 1,
14 
15     pub fn next(self: *Members) ?u32 {
16         if (self.index >= count(self.group_bytes)) return null;
17         defer self.index += 1;
18         return word(self.group_bytes, self.index);
19     }
20 };
21 
22 pub fn bytes(object: ObjectFile, section: SectionHeader) model.Error![]const u8 {
23     if (section.entry_size != group_word_size or section.size % group_word_size != 0) {
24         return error.InvalidObject;
25     }
26     return sectionBytes(object.bytes, section);
27 }
28 
29 pub fn count(group_bytes: []const u8) usize {
30     return group_bytes.len / group_word_size;
31 }
32 
33 pub fn members(group_bytes: []const u8) Members {
34     return .{ .group_bytes = group_bytes };
35 }
36 
37 pub fn word(group_bytes: []const u8, index: usize) u32 {
38     return readU32(group_bytes, index * group_word_size);
39 }