Add Arborix section directory byte readers

This commit is contained in:
2026-05-07 12:28:14 -05:00
parent 1d84bf7cfa
commit a002365651
2 changed files with 177 additions and 0 deletions

View File

@@ -20,3 +20,58 @@ readArborixHeader = (bs :
(pair majorVersion
(pair minorVersion sectionCount))
afterSectionCount)))))
readSectionRecord = (bs :
bindResult (readBytes 2 bs)
(sectionId afterSectionId :
bindResult (readBytes 4 afterSectionId)
(offset afterOffset :
bindResult (readBytes 4 afterOffset)
(length afterLength :
ok
(pair sectionId
(pair offset length))
afterLength))))
readSectionDirectory_ = y (self sectionCount i bs acc :
matchBool
(ok (reverse acc) bs)
(bindResult (readSectionRecord bs)
(sectionRecord afterSectionRecord :
self sectionCount (succ i) afterSectionRecord (pair sectionRecord acc)))
(equal? i sectionCount))
readSectionDirectory = (sectionCount bs : readSectionDirectory_ sectionCount 0 bs t)
sectionRecordId = (sectionRecord :
matchPair
(sectionId _ : sectionId)
sectionRecord)
sectionRecordOffset = (sectionRecord :
matchPair
(_ payload :
matchPair
(offset _ : offset)
payload)
sectionRecord)
sectionRecordLength = (sectionRecord :
matchPair
(_ payload :
matchPair
(_ length : length)
payload)
sectionRecord)
lookupSectionRecord = y (self sectionId directory :
matchList
nothing
(sectionRecord rest :
matchBool
(just sectionRecord)
(self sectionId rest)
(bytesEq? sectionId (sectionRecordId sectionRecord)))
directory)
byteSlice = (offset length bytes : bytesTake length (bytesDrop offset bytes))