35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/slither/parser.rb', line 35
def parse_by_bytes
parsed = {}
all_section_lengths = @definition.sections.map(&:length)
byte_length = all_section_lengths.max
all_section_lengths.each do |bytes|
next unless bytes != byte_length
raise(
Slither::SectionsNotSameLengthError, "All sections must have the same number of bytes for parse by bytes"
)
end
while (record = @file.read(byte_length))
unless remove_newlines! && byte_length == record.length
parsed_line = parse_for_error_message(record)
raise(Slither::LineWrongSizeError, "Line wrong size: No newline at #{byte_length} bytes. #{parsed_line}")
end
record.force_encoding(@file.external_encoding)
@definition.sections.each do |section|
parsed = fill_content(record, section, parsed) if section.match(record)
end
end
@definition.sections.each do |section|
unless parsed[section.name] || section.optional
raise(Slither::RequiredSectionNotFoundError,
"Required section '#{section.name}' was not found.")
end
end
parsed
end
|