Open nomadbyte opened 2 years ago
@nomadbyte Looks like right now it won't be straightforward to implement using functionality currently available in KS.
Probably closest among the current proposals would be #538 — this speaks of a way to define sections using scanning of data stream for certain patterns and then one could have substreams based on these scans, e.g. something like:
seq:
- id: recs
scan-start: kaitai.bytes([0x5b, 0x5b, 0x5b])
scan-end: kaitai.bytes([0x5d, 0x5d, 0x5d])
type: record
repeat: eos
This is rather a question than an issue as such. I'm trying to define a
ksy
spec to parse a binary list of sections of variable size each. Sections contain data records of fixed format and have a delimiting section-header and section-footer, yet there's no explicit size of the section nor a number of the contained records.Here's a sample binary dump in hex:
The sections are delimited by
[[[
and]]]
header/footer records and each section has itsid
field (0x0 and 0x31 in this case). In this sample all records are of the same size: 16 bytes. The whole file size is fixed. The sections are followed by some unused 0-filled records of the same size.I was able to parse such format into one array of records of varying type (header, footer, data), like the following:
I wonder if such format could be defined in
ksy
so that it parses into a list of sections, something like:Is it possible to parse this into such a form with
ksy
?