Kaitai describes itself like this:
Kaitai Struct is a declarative language used to describe various binary data structures, laid out in files or in memory: i.e. binary file formats, network stream packet formats, etc.
The main idea is that a particular format is described in Kaitai Struct language (
.ksy
file) and then can be compiled withksc
into source files in one of the supported programming languages. These modules will include a generated code for a parser that can read the described data structure from a file or stream and give access to it in a nice, easy-to-comprehend API.
What this means is that if you know the file format of a binary file you want to parse, e.g. an SQLite3 db, or an old NES savegame, you can create a lua parser for that file that will make it much easier to consume that data in a playdate game. If you've ever tried to parse a binary file without a tool like this you will understand how useful this would be.
Ideally it would work something like this:
- Install the katai struct compiler
- Download the relevant .ksy format file (or write one yourself)
- Compile the format into a parser for your language of choice, e.g.:
kaitai-struct-compiler -t lua sqlite3.ksy
- That will create a file
sqlite3.lua
, then reading the db should be this easy:
local success = require 'sqlite3'
local db = Sqlite3:from_file('sqlite.db')
In my case I want to be able to parse and display the contents of a certain type of SQLite3 database on the device, but there is huge potential for other uses. One that comes to mind is porting old games that use binary file formats for their data files. There are many formats already contributed to the 'format gallery, some examples:
- NES files: .nes file format format spec for Kaitai Struct
- Heroes of Might and Magic save games .bmp file format of Heroes of Might and Magic format spec for Kaitai Struct
- 3D model files: Quake2 Quake 1 (idtech2) model format (MDL version 6) format spec for Kaitai Struct
- Image formats, video, networking etc.
I have spent the last couple of weeks trying to get a sqlite3 parser working in lua. Unfortunately the state of the lua side of Kaitai is pretty poor. There was a PR that tried to fix some of the problems but it seems to have been abandoned, that was followed by another PR which attempted to fix the original PR but it hasn't had activity in the last 6 months.
I managed to get my db file parsed and most of the data is there, but I think that overflow pages are not being linked correctly. I posted my experiences on the more active PR here: sqlite3: fix parser by milahu · Pull Request #661 · kaitai-io/kaitai_struct_formats · GitHub
Hopefully I will get some response there but in any case this seems like a worthwhile project, not just for my needs. Please post here or DM me if you have any questions or comments, or even better would like to help out.
thanks for your time! happy playdating